Click here to Skip to main content
15,883,957 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
SqlConnection sqlcon = new SqlConnection(@"Server=ADMIN-PC\SQLEXPRESS;Database=ELMANAR; Integrated Security = True");
        SqlDataAdapter da;
        DataTable dt1 = new DataTable();

        Data_Access_Layer.DataAccessLayer DAL = new Data_Access_Layer.DataAccessLayer();
        SqlCommand cmd = new SqlCommand();




        private void btnsave_Click(object sender, EventArgs e)
        {

            try
            {
              
                cmd.CommandType = CommandType.Text;
                cmd.Connection = sqlcon;

                cmd.CommandText = "insert into TBL_CATEGORYCUSTOMERS (catcustomer_id,catcustomer_name,catcustomer_note) values ('" + txtid.Text + "','" + txtname.Text + "','" + txtnote.Text + "')";
                sqlcon.Open();
                cmd.ExecuteNonQuery();
              
                    
                    MessageBox.Show("Saved");
                    sqlcon.Close();
                    dt1.Clear();
                    da.Fill(dt1);

                    btnsave.Enabled = false;
                    btnadd.Enabled = true;
                    txtid.Clear();
                    txtname.Clear();
                    txtnote.Clear();
                                    
            }
       

            catch { }
Posted
Updated 2-Dec-14 9:24am
v2

To check if a value exists then you use a Select statement. Just run the SELECT statement first, check the return value, then proceed as you need to.
 
Share this answer
 
To check if a value exists then you use a Select statement. Just run the SELECT statement first, check the return value, then proceed as you need to.




thank you but

How Can I do that
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900