Results 1 to 2 of 2

Thread: [RESOLVED] ERR: DELETE record syntax in C#

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Nov 2005
    Posts
    310

    Resolved [RESOLVED] ERR: DELETE record syntax in C#

    What is missing with my codes?
    It doesn't execute delete record.
    It takes no effect when execute.


    Code:
            {
                con = new SqlConnection();
                con.ConnectionString = "Data Source=.\\SQLEXPRESS;AttachDbFilename=C:\\MyRecords\\pData.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True";
                con.Open();
                string sql = "DELETE * FROM tblClients WHERE surName='Yong'";
                da = new SqlDataAdapter(sql, con);
                con.Close();
            }
    I want to delete specific record from my database.
    And also Edit record by using Primary Key. Without using Dataset.
    Last edited by dr_aybyd; Sep 19th, 2010 at 03:26 AM.
    VB 6.0 = "Self-Study" Then
    vb.NET = "Self-Study" Then
    C# = 'on going study.....

  2. #2

    Thread Starter
    Hyperactive Member
    Join Date
    Nov 2005
    Posts
    310

    Re: ERR: DELETE record syntax in C#

    Woaa... I got it now...
    After reading some manuals on SQL commands
    Here is my working codes.

    Code:
                con = new SqlConnection();
                con.ConnectionString = "Data Source=.\\SQLEXPRESS;AttachDbFilename=C:\\MyRecords \\pData.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True";
                SqlCommand nonqueryCommand = con.CreateCommand();
                con.Open();
                nonqueryCommand.CommandText = "DELETE FROM tblClients WHERE surName='Yong'";
                nonqueryCommand.ExecuteNonQuery();
                con.Close();
    VB 6.0 = "Self-Study" Then
    vb.NET = "Self-Study" Then
    C# = 'on going study.....

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width