hiiiiiiiii evryone,
plz help me out.i want to delete a record but not able to do so.plz check the code and rectify the mistake.it is giving some unknown error.thnqqq

private void button1_Click(object sender, EventArgs e)
        {
            int i;
           
          String  sqlvar =("Delete from emp where empno=" + textBox1.text);

          string conn1 = "Data Source=(local);" +
  "Initial Catalog=master;" +
  "Integrated Security=SSPI";
            SqlConnection cn=new SqlConnection(conn1);
            cn.Open();
         
            SqlCommand cmd = new SqlCommand(sqlvar,cn );
            i = cmd.ExecuteNonQuery();
            if (i > 0)
            {
                MessageBox.Show("cmd executed");
            }
            else
            {
                MessageBox.Show("not executed");
            }
        }

Recommended Answers

All 3 Replies

Hi,

Can you write back exact error message u get... with full description..

Regards,
Vidyadhar

and at which line (just to be sure)

Make sure your catalog is set to the correct database. Currently it is set to master which is the primary system database.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.