Hello all,
I have written code for deleting particular Id entered by the user in the text box. What i need is when i press on Delete button it should display if the Entered Id delete or not. can any one give me the code. I am able to delete but that condition i am unable to get. Please help
Delete user
3 Answers
Know the answer? Post it. Somebody with the same question will find it here.


Kirtan PatelRank #292 · 8.6K reputationPosted May 22, 2009, 7:47 AM EDT
with three Column
ID,Name,Age
Then Code will be like below
private void button1_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(@"Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Database1.mdf;Integrated Security=True;User Instance=True");
con.Open();
SqlCommand comm = new SqlCommand("select * from Users Where Id=" + textBox1.Text, con);
SqlDataAdapter da = new SqlDataAdapter(comm);
DataSet ds = new DataSet();
da.Fill(ds, "Vtable");
if (ds.Tables[0].Rows.Count > 0)
{
comm = new SqlCommand("delete from users where id=" + textBox1.Text,con);
comm.ExecuteNonQuery();
MessageBox.Show("Record Deleted!!");
}
else
{
MessageBox.Show("Record Not Exist");
}
}
Dorababu MekaRank #457 · 5.5K reputationPosted May 22, 2009, 8:05 PM EDT
Kirtan PatelRank #292 · 8.6K reputationPosted May 22, 2009, 10:55 PM EDT
You can name it Anything But I call it Virtual Table so called "VTable"