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 |