help me to execute this stmt

Posted by Shamil123 under C# on 2/7/2011 | Points: 10 | Views : 1204 | Status : [Member] | Replies : 2
hello friends,
pls help me to clear the mistake from this stmt.
when i click on button,the rows availabe in the gridview table should store in mysql DB.
when i click, its shows the error in below line
as:Input string was not in a correct format.
help me out...

<code>
strMySQLcmd = "insert into purchase(pid,ptype,bname,qty,amount,supname)values(" + Convert.ToInt32(purchaserow[0]) + ",'" + purchaserow[1] + "','" + purchaserow[2] + "'," + Convert.ToInt32(purchaserow[3]) + "," + Convert.ToDouble(purchaserow[4]) + ",'" + purchaserow[5] + "')";
</code>




Responses

Posted by: Sathya4260 on: 2/7/2011 [Member] Starter | Points: 25

Up
0
Down
Try this...

strMySQLcmd = "insert into purchase(pid,ptype,bname,qty,amount,supname)values(" + Convert.ToInt32(purchaserow[0]) + ",'" +Convert.ToString( purchaserow[1]) + "','" + Convert.ToString(purchaserow[2]) + "'," + Convert.ToInt32(purchaserow[3]) + "," + Convert.ToDouble(purchaserow[4]) + ",'" + Convert.ToString(purchaserow[5]) + "')";

Sathish Kumar S

Shamil123, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Tripati.patro on: 2/18/2011 [Member] Starter | Points: 25

Up
0
Down
Try this Code

strMySQLcmd = "insert into purchase(pid,ptype,bname,qty,amount,supname)values(" + Convert.ToInt32(purchaserow[0].Value.ToString()) + ",'" + purchaserow[1].Value.ToString() + "','" + purchaserow[2].Value.ToString() + "'," + Convert.ToInt32(purchaserow[3].Value.ToString()) + "," + Convert.ToDouble(purchaserow[4].Value.ToString()) + ",'" + purchaserow[5].Value.ToString() + "')";


You need to take care about null values for a particular cell.
For eg: purchaserow[4] can be null. If null then Convert.ToInt32(purchaserow[4]) or Convert.ToInt32(purchaserow[3].Value.ToString()) will give you error.

Hope this will help you.

B.Tripati Patro
Oracle Certified Associate

Shamil123, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response