Click here to Skip to main content
15,891,136 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am using following code to show data in Data GridView :
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
        ' cmbItemName.DataBindings.Add("Text", thisDataTable, "Item_name")
        ItemInvoiceNo = ItemInvoiceNo + 1


Like that i will add multiple items in single Data GridView / Invoice.
My question is through "dr = dt.NewRow()" this code in which table system create new Row. I am asking this question because i just want to show fields in Grid view but system gives an error " Input string was not in a correct format.Couldn't store <sylinder> in Item_type_code Column. Expected type is Int64."
whereas I am not saving any record in my tables.

Please help me.
Posted

1 solution

Input string was not in a correct format.Couldn't store in Item_type_code Column. Expected type is Int64."
Based on the error, Item_type_code is expected to be of type Int64. But, you are passing string:
C#
dr(2) = Convert.ToString(txtItemType.Text)

Check the database design. Based on the datatype expected, pass on the value accordingly.

For now, based on error, following should resolve:
C#
dr(2) = Convert.ToInt64(txtItemType.Text)

But, make sure the value has to be of Int64 type.
 
Share this answer
 
Comments
Yogi ,Pune 4-Jan-13 23:30pm    
Yes I understand there is data type mismatch error, but in which table i have to check table design "ItemMaster or Invoice"
My doubt is still same "dr = dt.NewRow()" through this statement in which table system create new row.

If you look at my code. I am creating new row & inserting value into it not in my actual tables/database,that's why i am confused how to resolved this error.
Are you want to see my database structure.
Sandeep Mewara 4-Jan-13 23:39pm    
Where ever your reference to 'dt' is! This table is expecting certain column types. You need to make sure the same is passed.

Further, it's not about changing your datatype - instead it is about changing your input in the line below and making sure that correct data is passed:
dr(2) = Convert.ToString(txtItemType.Text)
Yogi ,Pune 4-Jan-13 23:48pm    
"Where ever your reference to 'dt' is! This table is expecting certain column types. You need to make sure the same is passed."
Please explain your statement in detail.I am unable to understand "reference to 'dt'". As per my code & tables i mentioned above can you give me which is reference table in my code.

Thank you
Sandeep Mewara 4-Jan-13 23:53pm    
GridItem.DataSource = dt.DefaultView
See where you populate this and you will know the source. You are just adding an extra row to some data previously fetched.

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