c# 注册窗体
d button1_Click(object sender, EventArgs e)函数中添加 如下代码: string thisConnectin = "server=XIAOLI-PC\\XIAOLI;Integrated Security=true;database=map"; SqlConnection con; con = new SqlConnection(thisConnectin); if (this.CheckInfo()) { string cmd = "INSERT INTO tb_user VALUES('" + textBox1.Text + "','" + textBox2.Text + "')"; SqlCommand com = new SqlCommand(cmd, con); con.Open();//关?闭? //com.ExecuteNonQuery(); if (com.ExecuteNonQuery() != 0)//com.ExecuteNonQuery()执′行D语?句?,?并¢返う?回?受酣?影?响ì行D数簓 MessageBox.Show("注痢?册á成é功|!?"); else MessageBox.Show("注痢?册á不?成é功|!?"); con.Close();//关?闭? Form3 frm2 = new Form3(); frm2.Show(); }
按钮函数中调用了两个自写的函数Alert()和checkInfo()函数 这两个函数的作用是为了确认编辑框中是否为空,以及密码和确认密码的值是否一致。 void Alert(string message) { MessageBox.Show(null, message, "信?息¢提?示?", MessageBoxButtons.OK, MessageBoxIcon.Information); } bool CheckInfo() { if ( this.textBox1.Text.Trim()== "") { Alert("用?户§名?不?完?整?"); return false; } if (this.textBox2.Text.Trim() == "") { Alert("密ü码?不?完?整?"); return false; } if (this.textBox3.Text.Trim() == "") { Alert("确ā?认?密ü码?不?完?整?"); return false; } if (this.textBox2.Text.Trim ()!= this.textBox3.Text.Trim()) { Alert("密ü码?和í确ā?认?密ü码?不?一?致?"); return false; } return true;