Click here to Skip to main content
Sign Up to vote bad
good
See more: VB.NET
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
 
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 in Item_type_code
Column. Expected type is Int64.
I am unable to find exact problem.Please help me.
Posted 31 Dec '12 - 5:21


1 solution

"
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,
 
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.
  Permalink  
Comments
Adam R Harris - 31 Dec '12 - 11:49
Convert.ToInt32(txtQty.Text); Should be Convert.ToInt32((string.IsNullOrEmpty(txtQty.Text) ? 0 : txtQty.Text));
Yogi ,Pune - 2 Jan '13 - 5:31
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)

  Print Answers RSS
Your Filters
Interested
Ignored
     
0 Arun Vasu 394
1 OriginalGriff 370
2 Sergey Alexandrovich Kryukov 313
3 Tadit Dash 213
4 Maciej Los 191
0 Sergey Alexandrovich Kryukov 9,955
1 OriginalGriff 7,589
2 CPallini 4,028
3 Rohan Leuva 3,422
4 Maciej Los 2,949


Advertise | Privacy | Mobile
Web01 | 2.6.130523.1 | Last Updated 31 Dec 2012
Copyright © CodeProject, 1999-2013
All Rights Reserved. Terms of Use
Layout: fixed | fluid