50
sqlCon.Open();
51
sqlComm = new SqlCommand("queryStuNameById", sqlCon);
52
//设置命令的类型为存储过程
53
sqlComm.CommandType = CommandType.StoredProcedure;
54
55
//设置参数
56
sqlComm.Parameters.Add("@stuId", SqlDbType.VarChar);
57
//注意输出参数要设置大小,否则size默认为0,
58
sqlComm.Parameters.Add("@stuName", SqlDbType.VarChar, 10);
59
//设置参数的类型为输出参数,默认情况下是输入,
60
sqlComm.Parameters["@stuName"].Direction = ParameterDirection.Output;
61
62
//为参数赋值
63
sqlComm.Parameters["@stuId"].Value = "1234";
64
//执行
65
sqlComm.ExecuteNonQuery();
66
//得到输出参数的值,把赋值给name,注意,这里得到的是object类型的,要进行相应的类型轮换
67
name = sqlComm.Parameters["@stuName"].Value.ToString();
68
sqlCon.Open();51
sqlComm = new SqlCommand("queryStuNameById", sqlCon);52
//设置命令的类型为存储过程53
sqlComm.CommandType = CommandType.StoredProcedure;54

55
//设置参数56
sqlComm.Parameters.Add("@stuId", SqlDbType.VarChar);57
//注意输出参数要设置大小,否则size默认为0,58
sqlComm.Parameters.Add("@stuName", SqlDbType.VarChar, 10);59
//设置参数的类型为输出参数,默认情况下是输入,60
sqlComm.Parameters["@stuName"].Direction = ParameterDirection.Output;61

62
//为参数赋值63
sqlComm.Parameters["@stuId"].Value = "1234";64
//执行65
sqlComm.ExecuteNonQuery();66
//得到输出参数的值,把赋值给name,注意,这里得到的是object类型的,要进行相应的类型轮换67
name = sqlComm.Parameters["@stuName"].Value.ToString();68
诗词在线
http://www.chinapoesy.com
诗词在线 |唐诗|宋词|元曲|现代诗歌|外国诗歌
126在线阅读网
http://www.Read126.cn
126在线阅读网 人物传记、古典名著、历史书籍。。。
http://www.chinapoesy.com
诗词在线 |唐诗|宋词|元曲|现代诗歌|外国诗歌
126在线阅读网
http://www.Read126.cn
126在线阅读网 人物传记、古典名著、历史书籍。。。
浙公网安备 33010602011771号