如何创建存储过程
user testdatabase(数据库名称)
go
create procedure testname(存储过程名称)
@test1 int, @test2 nvarchar(50)
as
insert into testtable values(@test1,@test2)
return
//select * from users where truename like '%[王刘]%' //只能分词查询,查询姓刘和姓王的信息
2 如何使用
public string[] TestLogin(string uname, string upwd)
{
try
{
SqlCommand cmd = new SqlCommand();
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText = "User_Login";//存储过程名
cmd.Connection = conn;
cmd.Parameters.Clear();
cmd.Parameters.Add("@uname", SqlDbType.NVarChar, 100).Value = uname;
cmd.Parameters.Add("@upwd", SqlDbType.NVarChar, 100).Value = upwd;
string[] result = new string[3];
conn.Open();
SqlDataReader dr = cmd.ExecuteReader();
if (dr.Read())
{
result[0] = dr["qx"].ToString();
result[1] = dr["tname"].ToString();
result[2] = dr["unitid"].ToString();
dr.Close();
return result;
}
else
{
return null;
}
}
catch (Exception e)
{
throw e;
}
finally
{
conn.Close();
}
}
最新内容请见作者的GitHub页:http://qaseven.github.io/