Dear All, private void btnSave_Click(object sender, EventArgs e) { string connstr = @"Server=.\SQLEXPRESS ;Initial Catalog=RPSJDB;Integrated Security=True; Max Pool Size=100"; SqlDataReader reader = null; SqlConnection conn = null; try { string query = "insert
into CustomerTable values('" + txtCustomerName.Text + "','" + txtAddress.Text + "','" + txtMobileNo.Text + "','" + lblGoldBalance.Text + "','" + lblSilverBalance.Text + "','" + lblCashBalance.Text + "')"; conn = new SqlConnection(connstr); if (txtCustomerName.Text
!= "" & txtAddress.Text != "") { conn.Open(); //Checking User Name Exists in CustomerTable string query1 = "select txtCustomerName from CustomerTable where txtCustomerName='" + txtCustomerName.Text + "'"; SqlCommand cmd = new SqlCommand(query1,conn); reader
= cmd.ExecuteReader(); if (reader != null && reader.HasRows) { //User exists in db do something MessageBox.Show("User Already Exists!!"); } else { SqlCommand cmd1 = new SqlCommand(query, conn); cmd1.ExecuteNonQuery(); txtCustomerName.Clear(); txtAddress.Clear();
txtMobileNo.Clear(); MessageBox.Show("Values Save in DataBase"); } reader.Close(); 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); } finally { reader.Close(); conn.Close(); } it show an error when i am fill only Customer name value then save (here it's show an error "only Mobile field can be empty" but it is not show.) it show a new error is : "There is already an openDataReader
associated with this command which must be close first." i am already close the reader.
↧