0

I am using C#.net.I want to delete a datarow from the sql server database table when the delete button is clicked.Specific row should be selected according to a text field value.Say user enters a userID to a text box...then he clicks delete button to delete the relavent row.
Please help me to do this.I am new to .net stuf and can't get through this.

Thanks

Nishara

2
Contributors
1
Reply
2
Views
8 Years
Discussion Span
Last Post by sknake
1
private static int DeleteRecord(string ID)
    {
      const string connStr = @"Data Source=apex2006sql;Initial Catalog=Leather;Integrated Security=True;";
      const string query = "Delete From UserTable Where ID = @ID";
      using (SqlConnection conn = new SqlConnection(connStr))
      {
        conn.Open();
        using (SqlCommand cmd = new SqlCommand(query, conn))
        {
          cmd.Parameters.Add(new SqlParameter("@ID", SqlDbType.VarChar)).Value = ID;
          return cmd.ExecuteNonQuery();
        }
      }
    }
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.