0

I have a string that I need to convert to int before updating it in my database, but haven't managed to figure out how it's done. Here's my latest try:

int iLager = Int32.Parse(TextBoxProdNumberOf.Text);

        SqlConnection conn = new SqlConnection(config);
        conn.Open();
        string sql = "UPDATE Produkter SET iLager ='" + iLager + "' WHERE ID ='" + ID + "'";
        SqlCommand comm = new SqlCommand(sql, conn);
        comm.ExecuteNonQuery();//Conversion failed when converting the varchar value '__Page' to data type int.

I've also tried:
string iLager = Convert.ToInt32(TextBoxProdNumberOf.Text);
string iLager = int.Parse(TextBoxProdNumberOf.Text);

Any ideas? Thanks in advance!

1
Contributor
1
Reply
2
Views
7 Years
Discussion Span
Last Post by BonaDrag
0

The error wasn't in the conversion, but in the sql statement. This is the solution:

string BildID = TextBoxPicID.Text;
int iLager = Int32.Parse(TextBoxProdNumberOf.Text);
 
        SqlConnection conn = new SqlConnection(config);
        conn.Open();
        string sql = "UPDATE Produkter SET iLager ='" + iLager + "' WHERE ID ='" + BildID + "'";
        SqlCommand comm = new SqlCommand(sql, conn);
        comm.ExecuteNonQuery();
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.