62,040
社区成员
发帖
与我相关
我的任务
分享
protected void Button1_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection("Data Source=(local);DataBase=db_JiaoYou;User ID=sa;PWD=67777");
con.Open();
string sql="select * from t1";
SqlCommand cmd=new SqlCommand(sql,con);
cmd.CommandType = CommandType.Text;
cmd.Parameters.Add(
new SqlParameter("ReturnValue", SqlDbType.Int, 4,
ParameterDirection.ReturnValue, false, 0, 0,
string.Empty, DataRowVersion.Default, null));
try
{
cmd.ExecuteNonQuery();
Response.Write((int)cmd.Parameters["ReturnValue"].Value);
}
catch (Exception err)
{
Label1.Text = err.Message;
}
}
private SqlCommand CreateCommand(string procName, SqlParameter[] prams)
{
// 确认打开连接
this.Open();
SqlCommand cmd = new SqlCommand(procName, con);
cmd.CommandType = CommandType.Text; //执行类型:命令文本
// 依次把参数传入命令文本
if (prams != null)
{
foreach (SqlParameter parameter in prams)
cmd.Parameters.Add(parameter);
}
// 加入返回参数
cmd.Parameters.Add(
new SqlParameter("ReturnValue", SqlDbType.Int, 4,
ParameterDirection.ReturnValue, false, 0, 0,
string.Empty, DataRowVersion.Default, null));
return cmd;
}
protected void Button1_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection("Data Source=(local);DataBase=db_JiaoYou;User ID=sa;PWD=67777");
con.Open();
string sql="select * from t1 where t1.parameter = @ReturnValue";
SqlCommand cmd=new SqlCommand(sql,con);
cmd.CommandType = CommandType.Text;
cmd.Parameters.Add(
new SqlParameter("ReturnValue", SqlDbType.Int, 4,
ParameterDirection.ReturnValue, false, 0, 0,
string.Empty, DataRowVersion.Default, null));
try
{
cmd.ExecuteNonQuery();
Response.Write((int)cmd.Parameters["ReturnValue"].Value);
}
catch (Exception err)
{
Label1.Text = err.Message;
}
}