在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
存储过程:
create proc proc_GetUserID
@UserName nvarchar(50),@ID int output as begin set @ID = (select ID from UserAccount where UserName = @UserName) end C#代码:
private void GetUserID(string userName)
{ SqlParameter[] paras = new SqlParameter[2]; paras[0] = new SqlParameter("@UserName", userName); paras[1] = new SqlParameter("@ID",SqlDbType.Int); paras[1].Direction = ParameterDirection.Output; object o = DataAccess.ExcuteNonQuery_Proc_Output("proc_GetUserID", paras, "@ID"); if (o == null || o.ToString() == "") { this.Label1.Text = "没有这个用户名"; } else { this.Label1.Text = o.ToString(); } }
public class DataAccess
{ public static object ExcuteNonQuery_Proc_Output(string procName, SqlParameter[] parameters,string outName) { SqlConnection conn = GetConnection(); SqlCommand cmd = new SqlCommand(); cmd.Connection = conn; cmd.CommandType = CommandType.StoredProcedure; cmd.CommandText = procName; for (int i = 0; i < parameters.Length; i++) { cmd.Parameters.Add(parameters[i]); } conn.Open(); int n = cmd.ExecuteNonQuery(); object o = cmd.Parameters[outName].Value; conn.Close(); return o; } } |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论