Below code throws SqlException on FillMethod "Primary Key Violation Error. Insert to the Table Failed". Not sure why in Fill Method. Its not happening everytime. Column1 and Column2 - Composite Key.
Dim ObjDAdapter As SqlDataAdapter
String selectstring = "select * from Table where Column1 = 'A' and Column2 = 'B'"
ObjDAdapter = New SqlDataAdapter(selectString, myConnection)
ObjDAdapter.Fill(Dataset)
ado.net
Regs,
Bharani
Please mark this post as "Answer" if it helped to solve your problem, so that others can also find it usefull while searching.
Dim ObjDAdapter As SqlDataAdapter
Dim objdataset As Dataset
String selectstring = "select * from Table where Column1 = 'A' and Column2 = 'B'"
ObjDAdapter = New SqlDataAdapter(selectString, myConnection)
ObjDAdapter.Fill(objdataset)
try the modified code. in your code you have not created instance for dataset. for filling data in data set you have to create it's instance
I think you should make sure that your primary key composite isn't duplicated. And I hope that you can try to do that by a test in the SQL Management Studio in a Stored Procdure first, and then refer this directly in the SqlDataAdapter.
Thanks for the reply. In the catch block i wrote the query from the variable to a log file, which gets generated when such exception is raised. i quried the generated query against the table. i got only one record for the condition or no record.
Regs,
Bharani
Please mark this post as "Answer" if it helped to solve your problem, so that others can also find it usefull while searching.
Bullonprowl
Member
338 Points
100 Posts
DataAdaptor.Fill(DataSet) - Primary Key Violation Error
Aug 17, 2012 01:12 PM|LINK
Platform : V4.0, SQL Server 2008, Windows 2003.
Below code throws SqlException on FillMethod "Primary Key Violation Error. Insert to the Table Failed". Not sure why in Fill Method. Its not happening everytime. Column1 and Column2 - Composite Key.
ado.net
Bharani
Please mark this post as "Answer" if it helped to solve your problem, so that others can also find it usefull while searching.
vinay13mar
Star
7756 Points
1626 Posts
Re: DataAdaptor.Fill(DataSet) - Primary Key Violation Error
Aug 17, 2012 01:17 PM|LINK
try the modified code.
in your code you have not created instance for dataset. for filling data in data set you have to create it's instance
V.K.Singh
Bullonprowl
Member
338 Points
100 Posts
Re: DataAdaptor.Fill(DataSet) - Primary Key Violation Error
Aug 17, 2012 01:20 PM|LINK
Hi Viny,
Its actually there. Not just mentioned it here.
Bharani
Please mark this post as "Answer" if it helped to solve your problem, so that others can also find it usefull while searching.
Decker Dong ...
All-Star
118619 Points
18779 Posts
Re: DataAdaptor.Fill(DataSet) - Primary Key Violation Error
Aug 19, 2012 01:47 AM|LINK
I think you should make sure that your primary key composite isn't duplicated. And I hope that you can try to do that by a test in the SQL Management Studio in a Stored Procdure first, and then refer this directly in the SqlDataAdapter.
Reguards!
Bullonprowl
Member
338 Points
100 Posts
Re: DataAdaptor.Fill(DataSet) - Primary Key Violation Error
Aug 20, 2012 04:15 AM|LINK
Hi Decker,
Thanks for the reply. In the catch block i wrote the query from the variable to a log file, which gets generated when such exception is raised. i quried the generated query against the table. i got only one record for the condition or no record.
Bharani
Please mark this post as "Answer" if it helped to solve your problem, so that others can also find it usefull while searching.
Decker Dong ...
All-Star
118619 Points
18779 Posts
Re: DataAdaptor.Fill(DataSet) - Primary Key Violation Error
Aug 20, 2012 04:41 AM|LINK
Hi again,
Would you mind showing me your table schema as welll as table records by scripting them and paste them here?
Reguards!