//System.Data.SqlClient.SqlParameter[] sqlParameters = new System.Data.SqlClient.SqlParameter[]{ }; System.Data.SqlClient.SqlParameter[] sqlParameters = new System.Data.SqlClient.SqlParameter[] { null, null };
//sqlParameters[0] = new System.Data.SqlClient.SqlParameter("@name","123");
System.Data.SqlClient.SqlParameter sp = new System.Data.SqlClient.SqlParameter("@name", "Pudding");
SQLHelper.ExecuteScalar(CommandType.Text, "select count(*) from xx where 姓名='@Name' and 电话='@tel'", sp); --不能带引号 object select_count = SQLHelper.ExecuteScalar(CommandType.Text, "select count(*) from xx where 姓名=@Name and 电话=@Tel ", sqlParameters); --这是正确的
System.Data.SqlClient.SqlParameter[] sqlParameters = new System.Data.SqlClient.SqlParameter[] {
new System.Data.SqlClient.SqlParameter("@Name", Name),
new System.Data.SqlClient.SqlParameter("@Tel", Tel)
};
通过遍历ht 返回一个数组
System.Data.SqlClient.SqlParameter[] sqlParameters
private static SqlParameter[] GetParameter(Hashtable ht)
{
SqlParameter[] parameters = new SqlParameter[ht.Count];
int i = 0;
foreach (string key in ht.Keys)
{
parameters[i] = new SqlParameter("@" + key, ht[key]);
i++;
}
return parameters;
}