Results 1 to 6 of 6

Thread: Violation of PRIMARY KEY constraint 'PK_t0011Journal'

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Jan 2007
    Posts
    24

    Violation of PRIMARY KEY constraint 'PK_t0011Journal'

    Dim query As String = "INSERT INTO [t0011Journal]([f0011Date],[f0011Memo],[f0011ClasificationCode],[f0011AccNumber],[f0011AccName],[f0011Debit],[f0011Credit],[f0011MonthYear])VALUES ('" & txtDate.Text & "','" & txtMemo.Text & "','" & txtClasifiCode.Text & "','" & txtAccNumber.Text & "','" & txtAccName.Text & "','" & txtTotal.Text & "','" & txtdech.Text & "','" & txtBlnThn.Text & "')"
    myDataAdapter = New SqlDataAdapter(query, strConnectionString)
    DS = New DataSet()
    myDataAdapter.Fill(DS, "t0011Journal")



    Dim query2 As String = "DELETE FROM [t005Temporary] WHERE ([f005AccNumber]='" & txtAccNumber.Text & "')"
    myDataAdapter2 = New SqlDataAdapter(query, strConnectionString)
    DS = New DataSet()
    myDataAdapter2.Fill(DS, "t005Temporary")


    this is my coding, when i run it the error display like that:

    Violation of PRIMARY KEY constraint 'PK_t0011Journal'. Cannot insert duplicate key in object 't0011Journal'.
    The statement has been terminated.


    Line 185: myDataAdapter2 = New SqlDataAdapter(query, strConnectionString)
    Line 186: DS = New DataSet()
    Line 187: myDataAdapter2.Fill(DS, "t005Temporary")Line 188:
    Line 189: End If

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,222

    Re: Violation of PRIMARY KEY constraint 'PK_t0011Journal'

    You're trying to Fill a DataTable with an INSERT statement. You execute a SELECT statement to get data.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Jan 2007
    Posts
    24

    Re: Violation of PRIMARY KEY constraint 'PK_t0011Journal'

    i dun understand ur answer, i want insert data into t0011journal and delete t005Temporary table.

    can u give me the correct code to delete data in table t005Temporary.

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,222

    Re: Violation of PRIMARY KEY constraint 'PK_t0011Journal'

    The Fill method of an SqlDataAdapter is used to execute a SELECT statement and populate a DataTable with the resulting data. If that's not what you want to do then you shouldn't be calling Fill.

    If you want to insert or delete a single record then you create an SqlCommand object and call its ExecuteNonQuery method.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  5. #5

    Thread Starter
    Junior Member
    Join Date
    Jan 2007
    Posts
    24

    Re: Violation of PRIMARY KEY constraint 'PK_t0011Journal'

    at before i used fill method for insert, it's working, data inserted in database, when i checked in database,data exist, now i'm so confused..can u give me link 0r tutorial that related for this topic

  6. #6
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,222

    Re: Violation of PRIMARY KEY constraint 'PK_t0011Journal'

    You could use a car to push a nail into a piece of wood but that doesn't make it the proper way to do it. There are numerous tutorial links in my signature. Take your pick.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

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