private void button4_Click(object sender, EventArgs e)//delete
        {
            conn.Open();

            comm.Connection = conn;
            comm.CommandText = " DELETE FROM Table1 WHERE Fname =" + textBox1.Text + "";

            dataGridView1.Update();
             conn.Close();

        }

HERE AM UNABLE TU DELETE THE RECORD IN MY DB ..

Recommended Answers

All 5 Replies

UNABLE TU DELETE

What does that mean? What happens when you execute the query?

" DELETE FROM Table1 WHERE Fname =" + textBox1.Text + ""

Why are you appending an empty string to the end of the query? The append would make sense if you were surrounding the text in single quotes:

"DELETE FROM Table1 WHERE Fname = '" + textBox1.Text + "'"

Try that.

The query can be a little clearer using string formatting:

String.Format(
    "DELETE FROM Table1 WHERE Fname = '{0}'",
    textBox1.Text
);

But really, you should be using parameterized queries.

there is no execution taking place..

there is no execution taking place..

It's hard to tell what's happening when you're using connection and command objects that are declared outside of the code shown. Somewhere you should be calling comm.ExecuteNonQuery().

thank you sir

this worked out well

 private void button4_Click(object sender, EventArgs e)//delete
        {
            comm.Connection = conn;
            comm.CommandText = " DELETE FROM Table1 WHERE Fname ='" + textBox1.Text + "'";
            conn.Open();
            comm.ExecuteNonQuery();
            conn.Close();
            dataGridView1.Update();

        }
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.