private void btsave_Click(object sender, EventArgs e) { int intnumrows; SqlConnection Conn = new SqlConnection(Con); Conn.Open(); String strSQL; strSQL = "SELECT COUNT(*) FROM Product WHERE ProID = '" + this.txtProID.Text + "' "; cmd = new SqlCommand(strSQL, Conn); intnumrows = Convert.ToInt32(cmd.ExecuteScalar()); if (intnumrows > 0) { MessageBox.Show("?????????????????????????????????????????? ????????????!", "?????????!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); txtProID.Focus(); } else { if (txtProID.Text == "" || txtproname.Text == "" || txtdetailpro.Text == "" || txtnuminventory.Text == "" || txtcost.Text == "" || txtprice.Text == "") { MessageBox.Show("?????????????????????????", "???????", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); txtProID.Focus(); } else { strSQL = "INSERT INTO Product(ProID,ProName,Detail,NumInventory,Cost,Price)" + " values(@ProID,@ProName,@Detail,@NumInventory,@Cost,@Price)"; // SqlCommand cmd = new SqlCommand("INSERT INTO Product(ProID,ProName,Detail,NumInventory,Cost,Price)" + // " values(@ProID,@ProName,@Detail,@NumInventory,@Cost,@Price)", Conn); cmd = new SqlCommand(strSQL, Conn); cmd.Parameters.AddWithValue("@ProID", txtProID.Text); cmd.Parameters.AddWithValue("@ProName", txtproname.Text); cmd.Parameters.AddWithValue("@Detail", txtdetailpro.Text); cmd.Parameters.AddWithValue("@NumInventory", txtnuminventory.Text); cmd.Parameters.AddWithValue("@Cost", txtcost.Text); cmd.Parameters.AddWithValue("@Price", txtprice.Text); try { Conn.Open(); cmd.ExecuteNonQuery(); ShowData(); MessageBox.Show("??????????????????????????", "?????????????????????", MessageBoxButtons.OK, MessageBoxIcon.Information); txtProID.Text = ""; txtproname.Text = ""; txtdetailpro.Text = ""; txtnuminventory.Text = ""; txtcost.Text = ""; txtprice.Text = ""; Conn.Close(); } catch (Exception) { MessageBox.Show("Error!! ?????????????????????????", "?????????", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); }
} } }
|