SqlCommand cmdadmin = new SqlCommand("loginvalidation");
cmdadmin.Connection = con;
cmdadmin.CommandType = CommandType.StoredProcedure;
SqlParameter paramadmin;
paramadmin = new SqlParameter("@vtype",drd1.ToString());
SqlParameter paramadmin1;
paramadmin1 = new SqlParameter("@username",Label1.Text);
cmdadmin.Parameters.Add(paramadmin1,paramadmin);
这是我的C#代码
我正在使用存储过程在select命令中显示以下结果但我不知道如何在select语句中使用多个参数
答案 0 :(得分:0)
存储过程中的select语句与此类似:
SELECT * FROM <YourTable> WHERE Column1=@vtype <AND/OR> Column2=@username
答案 1 :(得分:0)
你应该这样使用
SqlCommand cmdadmin = new SqlCommand("loginvalidation");
cmdadmin.Connection = con;
cmdadmin.CommandType = CommandType.StoredProcedure;
SqlParameter[] parameters ={
new SqlParameter("vtype",drd1.ToString()),
new SqlParameter("username",Label1.Text),
};
foreach (var p in parameters)
{
cmdadmin.Parameters.Add(parameters);
}
答案 2 :(得分:0)
要添加多个参数,您可以创建一个SqlParameter
SqlCommand sql = new SqlCommand();
SqlParameter[] parameter = {
new SqlParameter("@name", "Test"),
new SqlParameter("@age", "24")};
sql.Parameters.Add(parameter);
存储过程中的:
@name varchar(50)
@age nvarchar(10)
SELECT *
FROM <tableName>
WHERE Name = @name AND Age = @age
答案 3 :(得分:0)
SqlCommand cmdadmin = new SqlCommand("loginvalidation");
cmdadmin.Connection = con;
cmdadmin.CommandType = CommandType.StoredProcedure;
SqlParameter[] prms = new SqlParameter[]
{
new SqlParameter("@vtype", drd1.ToString()),
new SqlParameter("@username", Label1.Text)
};
cmdadmin.Parameters.AddRange(prms);