Click here to Skip to main content
15,886,033 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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

VB
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


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.
Posted

1 solution

"
CSS
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

"

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

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

Also you dont need to Convert.ToString on textbox.Text.
 
Share this answer
 
v2
Comments
Adam R Harris 31-Dec-12 11:49am    
Convert.ToInt32(txtQty.Text);
Should be
Convert.ToInt32((string.IsNullOrEmpty(txtQty.Text) ? 0 : txtQty.Text));
Yogi ,Pune 2-Jan-13 5:31am    
I understand there is problem of string & int value storage, but exactly where?
I am not storing a data into database. I stored it into datatable.
I checked datatable sequence it is all right.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900