|
-
Feb 13th, 2007, 03:34 AM
#1
Thread Starter
Junior Member
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
-
Feb 13th, 2007, 03:54 AM
#2
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.
-
Feb 13th, 2007, 04:13 AM
#3
Thread Starter
Junior Member
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.
-
Feb 13th, 2007, 04:19 AM
#4
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.
-
Feb 13th, 2007, 04:30 AM
#5
Thread Starter
Junior Member
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
-
Feb 13th, 2007, 04:52 AM
#6
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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|