Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem updating an Access DB with a DataTable when using stored procs

Status
Not open for further replies.

redav

Programmer
Mar 20, 2001
55
GB
Hi

This is a strange one.

I am updating an Access table from a DataTable and the same record is inserted multiple times when using a stored procedure but works OK if I build the update query in a string.

I am performing the update like this:-

Code:
daDataAdapter.InsertCommand = New OleDb.OleDbCommand("QRY_INSERT_LK_Domains_NameServers", cnSQL)
daDataAdapter.InsertCommand.CommandType = CommandType.StoredProcedure
daDataAdapter.InsertCommand.Transaction = txSQL

WorkParam = New OleDbParameter
WorkParam = daDataAdapter.InsertCommand.Parameters.Add("@iDomainID", OleDbType.Integer)
WorkParam.Value = iDomainID

WorkParam = New OleDbParameter
WorkParam = daDataAdapter.InsertCommand.Parameters.Add("@iNameServerID", OleDbType.Integer)
WorkParam.SourceColumn = "FK_NameServers_ID"
WorkParam.SourceVersion = DataRowVersion.Current

daDataAdapter.Update(dsDomain, "NameServers")

I have the following stored procedure:-

Code:
INSERT INTO LK_Domains_NameServers ( FK_Domains_ID, FK_NameServers_ID )
VALUES ([@iDomainID], [@iNameServerID]);

Now if the DataTable has four new rows, each with a different nameserverID then the first nameserverID is added four times. However, if I change it over to:-

Code:
daDataAdapter.InsertCommand = New OleDb.OleDbCommand(sSQL, cnSQL)
daDataAdapter.InsertCommand.CommandType = CommandType.Text
daDataAdapter.InsertCommand.Transaction = txSQL

And put the exact same SQL query in the sSQL string it works great and the four different records are inserted.

Anyone have any ideas on this. Is there a known issue when updating a table in Access from a DataTable using Stored Procedures. I have searched but cannot find anything.

Thanks for looking
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top