输入字符串格式不正确(在网格视图中添加值时) [英] Input string was not in a correct format (at the time of add values in Grid view)

查看:162
本文介绍了输入字符串格式不正确(在网格视图中添加值时)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在PO中添加项目。因为我正在使用Data Grideview。当用户点击添加按钮时,所有相关字段将添加到Data Grideview 中。喜欢所需的项目将放在PO中。我正在使用以下代码



I want to add items in PO.For that I am using Data Grideview . When user click on add button all the related fields will add in Data Grideview. like that required items will place in PO.I am using following code

Dim dr As DataRow
        dr = dt.NewRow()
        dr(0) = ItemInvoiceNo
        dr(1) = obj.ReturnString("Select Part_no From Item_Master Where Item_no=" & cmbPartNo.SelectedValue & "")
        dr(2) = Convert.ToString(txtItemType.Text)
        dr(3) = Convert.ToString(txtItemDesc.Text)
        dr(4) = Convert.ToInt32(txtQty.Text)
        dr(5) = Convert.ToInt32(txtRate.Text)
        dr(6) = Convert.ToInt32(txtDisc.Text)
        dr(7) = Convert.ToInt32(txtAmt.Text)
        dt.Rows.Add(dr)
        GridItem.DataSource = dt.DefaultView
        ItemInvoiceNo = ItemInvoiceNo + 1





表结构如下:

PO表

Item_PO_No

PO NO

货号

单位

数量

价格

光盘

Amt



物品大师

物品编号

描述

部件号

单位

增值税

项目类型代码





系统在博士后出错(2 )= Convert.ToString(txtItemType.Text)



错误:输入字符串的格式不正确。无法存储< gas>在Item_type_code中

列。预期的类型是Int64。

我无法找到确切的问题。请帮助我。



table structure is as follows:
PO Table
Item_PO_No
PO NO
Item No
Unit
Qty
Rate
Disc
Amt

Item Master
Item No
Desc
Part No
Unit
Vat
Item Type code


System give an error after dr(2) = Convert.ToString(txtItemType.Text)

Error:Input string was not in a correct format.Couldn''t store <gas> in Item_type_code
Column. Expected type is Int64.
I am unable to find exact problem.Please help me.

推荐答案

Error:Input string was not in a correct format.Couldn't store in Item_type_code
Column. Expected type is Int64.
I am unable to find exact problem.Please help m







因为你试图将字符串存储到int字段中,




"

Because you are trying to store a string into a int field,

Convert.ToInt32(txtQty.Text);
//Should be
Convert.ToInt32((string.IsNullOrEmpty(txtQty.Text) ? 0 : txtQty.Text));



你也不需要在textbox.Text上使用Convert.ToString。


Also you dont need to Convert.ToString on textbox.Text.


这篇关于输入字符串格式不正确(在网格视图中添加值时)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆