我有8个文本框和一个提交按钮。我只想在按下提交时只向db插入一个文本框值。因此,我必须按下提交按钮8次才能将所有文本框值输入到数据库中。
SqlConnection conn = new SqlConnection();
conn.ConnectionString = @"Data Source=Sadiq;Initial Catalog=rafi;Integrated Security=True";
conn.Open();
SqlCommand cmd = new SqlCommand();
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText = "student1";
int studid = Convert.ToInt32(TextBox1.Text);
string name = TextBox2.Text;
int age = Convert.ToInt32(TextBox3.Text);
string school = TextBox4.Text;
string clas = TextBox5.Text;
int marks = Convert.ToInt32(TextBox6.Text);
string grade = TextBox7.Text;
cmd.Parameters.Add(new SqlParameter("@stud_id", studid));
cmd.Parameters.Add(new SqlParameter("@name", name));
cmd.Parameters.Add(new SqlParameter("@age", age));
cmd.Parameters.Add(new SqlParameter("@school", school));
cmd.Parameters.Add(new SqlParameter("@class", clas));
cmd.Parameters.Add(new SqlParameter("@marks", marks));
cmd.Parameters.Add(new SqlParameter("@grade", grade));
cmd.Connection=conn;
cmd.ExecuteNonQuery();
conn.Close();