{
public partial class useradd : Form
{
public string newlimit;
public useradd(string newlimit)
{
this.newlimit = newlimit;
InitializeComponent();
} private static string connString = "Data Source=localhost;Initial Catalog=testsysdb;Integrated Security=True;Pooling=False"; public static string ConnString
{
get
{
return connString;
}
}
private void button2_Click(object sender, EventArgs e)
{
this.Close();//关闭该窗体
} private void button1_Click(object sender, EventArgs e)
{
string name=textBox1.Text;
string passwd=textBox2.Text;
string passwd2 = textBox3.Text;
string age = textBox4.Text;
string sex = ((this.radio_female.Checked == true) ? "男" : "女");
string add = textBox5.Text;
string email = textBox6.Text;
string telephone = textBox7.Text;
int flag = 0; if (passwd!=passwd2)
{
MessageBox.Show("密码确认有误!", "提示");
return;
}
if (name.Length == 0 || passwd.Length == 0 || age.Length == 0 || age.Length == 0 || sex.Length == 0 || add.Length == 0 | email.Length == 0)
{
MessageBox.Show("请添加完整的用户信息!", "添加用户提示");
return;
} SqlConnection conn = new SqlConnection(useradd.ConnString);
string sqlstr = "insert into userinfo values('" + name + "','" + passwd + "','" + newlimit + "','" + age + "','" + telephone + "','" + sex + "','" + add + "','" + email + "')";
SqlCommand command = new SqlCommand(sqlstr, conn);
conn.Open(); try
{
flag=command.ExecuteNonQuery();
if (flag>0)
{
MessageBox.Show("用户添加成功!", "添加用户提示");
this.Close();
}
else
{
MessageBox.Show("添加用户失败!", "添加用户提示");
}
}
catch (Exception err)
{
MessageBox.Show("系统错误:"+err.Message, "添加用户提示");
}
conn.Close();
} private void useradd_Load(object sender, EventArgs e)
{ } private void button2_Click_1(object sender, EventArgs e)
{
this.Close();
public partial class useradd : Form
{
public string newlimit;
public useradd(string newlimit)
{
this.newlimit = newlimit;
InitializeComponent();
} private static string connString = "Data Source=localhost;Initial Catalog=testsysdb;Integrated Security=True;Pooling=False"; public static string ConnString
{
get
{
return connString;
}
}
private void button2_Click(object sender, EventArgs e)
{
this.Close();//关闭该窗体
} private void button1_Click(object sender, EventArgs e)
{
string name=textBox1.Text;
string passwd=textBox2.Text;
string passwd2 = textBox3.Text;
string age = textBox4.Text;
string sex = ((this.radio_female.Checked == true) ? "男" : "女");
string add = textBox5.Text;
string email = textBox6.Text;
string telephone = textBox7.Text;
int flag = 0; if (passwd!=passwd2)
{
MessageBox.Show("密码确认有误!", "提示");
return;
}
if (name.Length == 0 || passwd.Length == 0 || age.Length == 0 || age.Length == 0 || sex.Length == 0 || add.Length == 0 | email.Length == 0)
{
MessageBox.Show("请添加完整的用户信息!", "添加用户提示");
return;
} SqlConnection conn = new SqlConnection(useradd.ConnString);
string sqlstr = "insert into userinfo values('" + name + "','" + passwd + "','" + newlimit + "','" + age + "','" + telephone + "','" + sex + "','" + add + "','" + email + "')";
SqlCommand command = new SqlCommand(sqlstr, conn);
conn.Open(); try
{
flag=command.ExecuteNonQuery();
if (flag>0)
{
MessageBox.Show("用户添加成功!", "添加用户提示");
this.Close();
}
else
{
MessageBox.Show("添加用户失败!", "添加用户提示");
}
}
catch (Exception err)
{
MessageBox.Show("系统错误:"+err.Message, "添加用户提示");
}
conn.Close();
} private void useradd_Load(object sender, EventArgs e)
{ } private void button2_Click_1(object sender, EventArgs e)
{
this.Close();
这样问题一目了然
http://www.cnblogs.com/alexis/archive/2010/11/06/1870519.html