0

i have promblem when using bottom update, when i get data in textbox, this is my code

string uSql;
uSql = "UPDATE Material SET MaterialName='"+txNama.Text+"',MatGroupID='"+cbGroup.Text+"' WHERE MaterialID='"+txKode.Text+"'";
SqlConnection conn = new SqlConnection(connetionString);

SqlCommand comand = new SqlCommand(uSql, conn);
                    conn.Open();
                    comand.Parameters.Add(new SqlParameter("@MaterialName", SqlDbType.NVarChar, 50));
                    comand.Parameters["@MaterialName"].Value = txNama.Text;
                    comand.Parameters.Add(new SqlParameter("@MatGroupID", SqlDbType.NVarChar, 20));
                    comand.Parameters["@MatGroupID"].Value = cbGroup.Text;

comand.ExecuteNonQuery();

...
i don't finding statement error from program

best regards,
maartin

Edited by mike_2000_17: Fixed formatting

3
Contributors
2
Replies
3
Views
7 Years
Discussion Span
Last Post by Ravenheart
0

Are You using query or stored procedure,all you created a query for update,so remove the parameters and put conn.open() on before of command creation.

conn.Open();

SqlCommand comand = new SqlCommand(uSql, conn);
0

uSql = "UPDATE Material SET MaterialName=@MaterialName,MatGroupID=@MatGroupID WHERE MaterialID=@MaterialID";

Add a MaterialID parameter and try using the above query.

This topic has been dead for over six months. 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.