First don't mark it as duplicate, because this
ExecuteNonQuery not working in C#
is not the solution i am looking, the syntax is correct, the connection also correct because the SqlDataReader is working, and i open the connection and called it in SqlCommand. Here is my code
if (sql_con.State == ConnectionState.Closed)
{
sql_con.Open();
}
StringBuilder query = new StringBuilder();
query.Append(String.Format("update tbl_userdata set stage=@stage where username=@name"));
SqlCommand sql_command2 = new SqlCommand(query.ToString(), sql_con);
sql_command2.Parameters.AddWithValue("@stage", stage);
sql_command2.Parameters.AddWithValue("@name", lblName.Text.ToLower());
sql_command2.ExecuteNonQuery();
And after debugging my query is update tbl_userdata set stage=@stage where username=@name
i don't know what's wrong here, i remove the where clause to see if thats the cause of the problem, but still error. I don't know what's wrong here
here is my connection
SqlConnection sql_con = new SqlConnection(Properties.Settings.Default.dbCon);
Sorry i forgot to put my error, the error is the stage is not updating, this is my table
tbl_userdata
+--------+-------+-------+
|Username|stage | coins |
+--------+-------+-------+
Username = nvarchar(5), stage = smallint, coins = smallmoney
ExecuteNonQuery(there isn't any) check your values and possible exceptions. The only difference between the two functions is that one returns the first available result value while the second does nothing after execution has finished.