Click here to Skip to main content
15,889,176 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi, how to solve this?

here, i give coding. i am getting error like failed to convert parameter value from a Label to a Int32, when debegger excutes on ExcuteNonQuery();

protected void utnclcicked(object sender, ImageClickEventArgs e)
{
for (int i = 0; i <= C1GridView1.Rows.Count-1; i++)
{

TextBox tqty1 = (TextBox)C1GridView1.Rows[i].Cells[7].FindControl("num");


TextBox l1= (TextBox)GridView1.Rows[i].Cells[0].FindControl("txtnote");
Label m1= (Label)GridView1.Rows[i].Cells[1].FindControl("lblmaxqty");
Label m2= (Label)GridView1.Rows[i].Cells[2].FindControl("lblminqty");
Label m3= (Label)GridView1.Rows[i].Cells[3].FindControl("lblivtfid");
Label m4= (Label)GridView1.Rows[i].Cells[4].FindControl("code");
Label m5= (Label)GridView1.Rows[i].Cells[6].FindControl("descript");
Label m6= (Label)GridView1.Rows[i].Cells[8].FindControl("lblprice");
Label m7= (Label)GridView1.Rows[i].Cells[8].FindControl("lblmfg");

int s1= Convert.ToInt32(tqty1.Text.ToString().Trim());
string s2= lisname.Text.ToString().Trim();
int s3= Convert.ToInt32( maxqty.Text.ToString().Trim());
int s4= Convert.ToInt32(minqty.Text.ToString().Trim());
int s5= Convert.ToInt32(pid.Text.ToString().Trim());
string s6= lblitem.Text.ToString().Trim();
string s7= des.Text.ToString().Trim();
decimal s8 = Convert.ToDecimal(price1.Text.ToString().Trim());

string s9= mfg1.Text.ToString().Trim();

string s10= Session["password"].ToString();
string s11= Session["LoggedIN"].ToString();
SqlConnection conlist = new SqlConnection(constring);
conlist.Open();

SqlCommand cmd = new SqlCommand("sp_testsp", conlist);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add("@t1", SqlDbType.NVarChar).Value = s1
cmd.Parameters.Add("@t2", SqlDbType.Int).Value = s2
cmd.Parameters.Add("@t3", SqlDbType.Int).Value = s3
cmd.Parameters.Add("@t4", SqlDbType.Int).Value = s4
cmd.Parameters.Add("@t5", SqlDbType.NVarChar).Value = s5
cmd.Parameters.Add("@t6", SqlDbType.NVarChar).Value = s6
cmd.Parameters.Add("@t7", SqlDbType.Int).Value = s7
cmd.Parameters.Add("@t8", SqlDbType.Decimal).Value = s8
cmd.Parameters.Add("@t9", SqlDbType.NVarChar).Value = s9
cmd.Parameters.Add("@t10", SqlDbType.NVarChar).Value = s10
cmd.Parameters.Add("@t11", SqlDbType.NVarChar).Value = s11
cmd.ExecuteNonQuery();
conlist.Close();


}
}



i am getting value from cells of gridview and converting from lablel, text value into int type and string type and then i am sending those values as parameteres for stored prrocedure "sp_testsp"..

Everthing works fine. while converting label and text to int and string, no error. but, when cursor(debugger) comes to cmd.ExecuteNonQuery() i am getting error follow:

Failed to convert parameter value from a Label to a Int32.

How to solve this ? why It says that failed to convert parameter value from a label to Int32. Help needed.
Posted
Updated 11-Dec-13 17:29pm
v2

Actually I think the error says something more like "unable to convert from string to int", not label.

The problem is S7, you are storing it in a string, but in your query parameters you have it set as an Int.

Here are the two lines, notice how s7 is stored in a string, and parameterized as an int.

C#
string s7= des.Text.ToString().Trim();
cmd.Parameters.Add("@t7", SqlDbType.Int).Value = s7;
 
Share this answer
 
v2
Comments
Suman Zalodiya 17-Dec-13 6:57am    
You need to check all the query parameter datatype and variable datatype because mostly it's looking like different datatype.
The Issue Ron Bayer already have pointed out. So try converting it as you are already doing for s3,s4,s5 .

command.Parameters.Add("@t7", SqlDbType.Int).Value = Convert.ToInt32(s7);


Hope this helps...
 
Share this answer
 
v3
Another way to handle null and convert string to int.
int s7=0;
if(!string.isnullorempty(des.Text))
s7=convert.toint32(des.Text.trim());
 
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