黑马程序员技术交流社区
标题:
存储过程的调用
[打印本页]
作者:
张彪
时间:
2011-11-30 08:15
标题:
存储过程的调用
本帖最后由 张彪 于 2011-12-1 08:26 编辑
怎么把已经写好的储存过程和视图在程序中调用?使用存储过程和在程序中用select语句有什么不同?
作者:
王硕
时间:
2011-11-30 08:38
第一个问题我在网上找了一些资料,你可以看看,上面将的很详细,http://hi.baidu.com/wangzhiqing999/blog/item/0c2fd3ad17aee6f31f17a263.html
对于第二个问题,我的理解是:对于使用只有参数不同,结构相同的sql语句,使用存储过程会很方便,不用重复写sql语句。
作者:
王绚文
时间:
2011-11-30 11:06
private void button1_Click(object sender, EventArgs e)
{
string username = txt_username.Text.Trim();
string sex = cob_sex.Text.Trim();
string createtime = dt_time.Value.Date.ToShortDateString();
string tel = txt_tel.Text.Trim();
if (checkTextbox() == true)
{
try
{
myConn = new SqlHelper().conn;
SqlCommand cmd = new SqlCommand("SP_insertuser", myConn);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add("@username", SqlDbType.VarChar).Value = username;
cmd.Parameters.Add("@sex", SqlDbType.Char).Value = sex;
cmd.Parameters.Add("@createtime", SqlDbType.Char).Value = createtime;
cmd.Parameters.Add("@tel", SqlDbType.VarChar).Value = tel;
myConn.Open();
int res = (int)cmd.ExecuteNonQuery();
myConn.Close();
if (res == 1)
{
MessageBox.Show("新增用户成功!", "", MessageBoxButtons.OK, MessageBoxIcon.Information);
BangDing();
txt_username.Text = string.Empty;
txt_tel.Text = string.Empty;
}
else
{
MessageBox.Show("新增用户失败!", "", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
catch (Exception ex)
{
MessageBox.Show("错误提示:"+ex.Message);
return;
}
finally
{
if (myConn.State.ToString().ToLower() == "open")
{
myConn.Close();
}
}
}
else
{
MessageBox.Show("信息非法,请检查信息,修改后再次提交!","出错啦!",MessageBoxButtons.OK,MessageBoxIcon.Error);
return;
}
}
______________________________________________
转自我的博客
你可以去我博客看看
http://www.cnblogs.com/xuanwen
欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/)
黑马程序员IT技术论坛 X3.2