protected void Button5_Click(object sender, EventArgs e) { String sqlconn = "Data Source=localhost;Initial Catalog=classData;User ID=sa;pwd=;Integrated Security=True"; SqlConnection myConnection = new SqlConnection(sqlconn); //实例化一个command SqlCommand myCommand = new SqlCommand("add_info", myConnection); //定义访问数据库的方式是存储过程 myCommand.CommandType = CommandType.StoredProcedure; myCommand.Parameters.Add("@pname", SqlDbType.VarChar, 10); myCommand.Parameters["@pname"].Direction = ParameterDirection.Input; myCommand.Parameters["@pname"].Value = TextBox5.Text; myCommand.Parameters.Add("@pno", SqlDbType.VarChar, 10); myCommand.Parameters["@pno"].Direction = ParameterDirection.Input; myCommand.Parameters["@pno"].Value = TextBox6.Text; myCommand.Parameters.Add("@ppro", SqlDbType.VarChar, 10); myCommand.Parameters["@ppro"].Direction = ParameterDirection.Input; myCommand.Parameters["@ppro"].Value = TextBox7.Text; myCommand.Parameters.Add("@pid", SqlDbType.VarChar, 10); myCommand.Parameters["@pid"].Direction = ParameterDirection.Input; myCommand.Parameters["@pid"].Value = TextBox8.Text; myConnection.Open(); myCommand.ExecuteNonQuery(); string name = myCommand.Parameters["@pname"].Value.ToString(); string no = myCommand.Parameters["@pno"].Value.ToString(); string pro = myCommand.Parameters["@ppro"].Value.ToString(); string id = myCommand.Parameters["@pid"].Value.ToString(); Response.Write("<script language=javascript>alert('记录添加成功!');</script >"); myConnection.Close(); }