SqlConnection myConnection = new SqlConnection(ConfigurationSettings.AppSettings["ConnectionString"]);
SqlCommand myCommand = new SqlCommand("AddGuestBook",myConnection);
myCommand.CommandType = CommandType.StoredProcedure; //设置命令字符串为存储过程
//下面是设置存储过程所需要的参数 parameterUserName是实参 @UserName是形参 userName是变量
SqlParameter parameterUserName = new SqlParameter("@UserName",SqlDbType.NVarChar,50);parameterUserName.Value=userName;
myCommand.Parameters.Add(parameterUserName);
//打开连接,执行存储过程后关闭
myConnection.Open();
myCommand.ExecuteNonQuery();
myConnection.Close();
浙公网安备 33010602011771号