Click here to Skip to main content
15,889,808 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi ,

Here I have write code for gridview to insert record but that is through a error "Input string was not in a correct format"
sqlInsert.Parameters.Add("@Product_Quantity", SqlDbType.Int).Value = Convert.ToInt32(newProduct_Quantity.Text);


while I have checked all things product_quantity is a int field in database and same write in code but I do not know the reason.
while i am able to update and delete row but when insert record then the error is coming.
Posted
Updated 29-Sep-10 20:15pm
v3
Comments
[no name] 30-Sep-10 14:45pm    
Is that the only parameter?

Please post the entire grid markup

Check the value for the parameter @Product_Quantity while debugging, is it numeric value? i think it's not. Basically this error occurs at these times.
Also check if the value is ""(blank string), so convert it.
 
Share this answer
 
v3
Use int.Parse or int.TryParse rather than Convert.ToInt32. Confirm you are entering a valid string. Split the code into different lines so you can tell exactly where the error is:
C#
int productQuantity = int.Parse(newProduct_Quantity.Text);
sqlInsert.Parameters.Add("Product_Quantity", SqlDbType.Int).Value = productQuantity;

Also note that you don't need the "@" in front of the variable... that will be added for you. If you are calling a stored procedure, make sure the parameter is the right type. If you are using an INSERT statement, make sure all the parameters and values are in an order that corresponds to eachother.
 
Share this answer
 

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