本文共 897 字,大约阅读时间需要 2 分钟。
如何创建存储过程
user testdatabase(数据库名称)gocreate procedure testname(存储过程名称)@test1 int, @test2 nvarchar(50)asinsert 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://dkalx.baihongyu.com/