How can I delete table values from database using c#, but by asking from user not hard coded values ?
I write the code but it's not working check it out....
Loading
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Munesh SharmaRank #174 · 13.9K reputationPosted Apr 1, 2014, 8:32 PM EDT
private void delete_btn_Click(object sender, EventArgs e)
{
if (!(textBox1.Text == string.Empty && textBox2.Text == string.Empty))
{
string str = "server = MUNESH;Database=data;UID=sa;Password=reladmin";
SqlConnection con = new SqlConnection(str);
string query = "Delete from registration where ID= '" + this.textBox1.Text + "' and Password = '" +this.textBox2.Text + "'";
SqlCommand cmd = new SqlCommand(query, con);
SqlDataReader myreader;
try
{
con.Open();
myreader = cmd.ExecuteReader();
MessageBox.Show("Deleted", "user information");
while (myreader.Read())
{
}
con.Close();
}
catch (Exception ec)
{
MessageBox.Show(ec.Message);
}
}
else
{
MessageBox.Show("enter ID or password which you want to delete");
}
}
Shweta LodhaRank #31 · 39.8K reputationPosted Apr 1, 2014, 11:20 AM EDT
Jignesh TrivediRank #16 · 50.3K reputationPosted Apr 1, 2014, 8:19 PM EDT
hi,
Can you please provide more information like what technologies you are using win forms or web or mvc and ofcourse your code.
also refer below link
http://www.onlinebuff.com/article_step-by-step-select-insert-update-and-delete-using-aspnet-c-and-adonet_32.html
http://www.dreamincode.net/forums/topic/238727-insert-update-and-delete-records-in-table-with-datagridview-using-c%23/
hope this will help you.
Abhay ShankerRank #375 · 6.7K reputationPosted Apr 1, 2014, 8:58 PM EDT
Ahsan Abbas8 reputationPosted Apr 2, 2014, 1:38 PM EDT