Click here to Skip to main content
12,507,674 members (56,991 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: VB 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
Posted 31-Dec-12 5:21am

1 solution

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

Solution 1

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.160927.1 | Last Updated 31 Dec 2012
Copyright © CodeProject, 1999-2016
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