Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: VB.NET
I am using following code to show data in Data GridView :
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 in Item_type_code Column. Expected type is Int64."
whereas I am not saving any record in my tables.
 
Please help me.
Posted 4-Jan-13 2:45am

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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:
  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:
  dr(2) = Convert.ToInt64(txtItemType.Text)
But, make sure the value has to be of Int64 type.
  Permalink  
Comments
Yogi ,Pune at 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 at 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 at 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 at 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)

  Print Answers RSS
0 OriginalGriff 530
1 George Jonsson 275
2 Sergey Alexandrovich Kryukov 264
3 Maciej Los 260
4 Garth J Lancaster 208
0 Sergey Alexandrovich Kryukov 10,879
1 OriginalGriff 5,555
2 Maciej Los 5,534
3 CPallini 3,819
4 BillWoodruff 3,594


Advertise | Privacy | Mobile
Web01 | 2.8.141030.1 | Last Updated 4 Jan 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100