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.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Munesh SharmaPosted Apr 2, 2014, 12:32 AM
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");
}
}
Ahsan AbbasPosted Apr 2, 2014, 5:38 PM
Abhay ShankerPosted Apr 2, 2014, 12:58 AM
Jignesh TrivediPosted Apr 2, 2014, 12:19 AM
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.
Shweta LodhaPosted Apr 1, 2014, 3:20 PM