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

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();
        }
      }
    }
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.