I have a little problem in ASP.NET. I'm trying to get the MAX number in a column and then increment it by 1. Like this in example:
SqlConnection con= new SqlConnection(ConfigurationManager.ConnectionStrings["ConnString"].ConnectionString);
con.Open();
string db = "instert into FJ(C1, C2, C3) values (@c1 , @c2 ,@c3)";
SqlCommand com = new SqlCommand(db, con);
com.Parameters.AddWithValue("@c1", TextBox1.Text);
com.Parameters.AddWithValue("@c2", com .CommandText = "declare @a float set @a = (select MAX(C2) from FJ)+1 INSERT INTO [FJ]([C2]) VALUES (@a)");
com.Parameters.AddWithValue("@c3", TextBox3.Text);
com.ExecuteNonQuery();
con.Close();
The thing that column C2 is incremented by 1 but other columns are null. If I comment C2 line TextBox1 and 3 are added to the database. What is the problem?
P.S. I'm not allowed to edit the database. I need to make it in ASP.NET code.