Dear All, How could be stop the duplicate name when I click on save button and tell me it’s already exists i am using above code for save name ,address etc. from the database. private void btnSave_Click(object sender, EventArgs e) { try { string connstr = @"Server=.\SQLEXPRESS
;Initial Catalog=RPSJDB;Integrated Security=True; Max Pool Size=100"; string query = "insert into CustomerTable values('" + txtCustomerName.Text + "','" + txtAddress.Text + "','" + txtMobileNo.Text + "','" + lblGoldBalance.Text + "','" + lblSilverBalance.Text+ "','" + lblCashBalance.Text + "')"; SqlConnection conn = new SqlConnection(connstr); if (txtCustomerName.Text != "" & txtAddress.Text != "") { conn.Open(); SqlCommand cmd = new SqlCommand(query, conn); cmd.ExecuteNonQuery(); txtCustomerName.Clear(); txtAddress.Clear();
txtMobileNo.Clear(); MessageBox.Show("Values Save in DataBase"); conn.Close(); } else { MessageBox.Show("Only Mobile Field Can be Empty"); } } catch (Exception ex) { MessageBox.Show("At Least 0 value can be save in the Gold Silver Cash Area",ex.Message); }
↧