namespace JinXiaoCun { public partial class frmAddCustomer : Form { public frmAddCustomer() { InitializeComponent(); } private void btnAddCustomer_Click(object sender, EventArgs e) { //insert into customer values('Cu01','陈工','男','13715687896') string cusId = this.txtCusId.Text.Trim(); string cusName = this.txtCusName.Text.Trim(); string cusSex = this.cmbCusSex.Text; string cusPhone = this.txtCusPhone.Text.Trim(); string strsql = "insert into customer values('" + cusId + "','" + cusName + "','" + cusSex + "','" + cusPhone + "')"; string conString = "Server=.;database=JinXiaoCun;uid=sa;pwd=sasa"; SqlConnection con = new SqlConnection(conString); con.Open(); SqlCommand cmd = new SqlCommand(strsql, con); cmd.ExecuteNonQuery(); con.Close(); this.txtCusId.Text = ""; this.txtCusName.Text = ""; this.cmbCusSex.Text = ""; this.txtCusPhone.Text = ""; MessageBox.Show("添加成功"); } } }