Quantcast
Channel: Visual Studio and Visual Web Developer Express
Viewing all articles
Browse latest Browse all 3509

"Error converting data type varchar to numeric".

$
0
0
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 { if (reader != null) { reader.Close(); // close the reader before making a new connection } 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 { if (reader != null) { reader.Close(); } if (conn != null) { conn.Close(); } } it show an error when i m not write any value in MobileNo Field. if put the value in all the textboxes then save the value perfectly. i want it show the "Only Mobile Field Can be Empty" message when it blank.so tell me what's the wrong in my code. "Error converting data type varchar to numeric".

Viewing all articles
Browse latest Browse all 3509

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>