我需要帮助..请告诉我我在这段代码中做错了什么,我在将参数数组传递给命令时搞砸了。我的存储过程是正确的,连接字符串也是正确的..
internal string addmember(string name, string dob, string city, string state, string mobile, string email, string pass)
{
List<SqlParameter> param = new List<SqlParameter>();
param.Add(new SqlParameter("@Mname",Convert.ToString(name)));
param.Add(new SqlParameter("@Mdob",Convert.ToString(dob)));
param.Add(new SqlParameter("@MemailId",Convert.ToString(email)));
param.Add(new SqlParameter("@Mpassword", Convert.ToString(email)));
param.Add(new SqlParameter("@McontactNo", Convert.ToString(mobile)));
param.Add(new SqlParameter("@Mcity", Convert.ToString(city)));
param.Add(new SqlParameter("@Mstate", Convert.ToString(state)));
string result = Convert.ToString(executescaler(con, CommandType.StoredProcedure, "add_members", param.ToArray()));
return result;
}
private string executescaler(string con, CommandType commandTyp, string procedure, SqlParameter[] sqlParameter)
{
string res;
using (SqlConnection connection = new SqlConnection(con))
{
connection.Open();
SqlCommand cmd = new SqlCommand(procedure, connection);
cmd.CommandType = commandTyp;
cmd.CommandText = procedure;
cmd.Parameters.AddRange(sqlParameter);
res= cmd.ExecuteNonQuery().ToString();
}
return res;
}
通常我使用 sqlhelper,所以永远不需要经过深思熟虑.. 但现在我正因为这个而痛苦..我不知道如何将 sqlparameter 数组传递给命令