Access Table Load

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I'm using a VB.Net interface to load an Access table. The relationship is 1
input record to many table rows. The problem is that the first name of the
first row is populated for every row on the table (which curiously has the
correct total number of rows for the input file!). The reader does read the
data correctly.

If I put all the input record data into one row, it works perfectly.

Here's the partial code:

Dim objData as New DALBase
objData.SQL = "usp_LoadImportTable"
objData.InitializeCommand()

Line = objReader.ReadLine

' Code to read the input file and split the data into the desired fields -
works great.

objData.AddParameter("@ID", OleDb.OleDbType.VarChar, 10, strID)
objData.AddParameter("@Name", OleDb.OleDbType.VarChar, 50, strName1)
Call LoadTable()

objData.AddParameter("@ID", OleDb.OleDbType.VarChar, 10, strID)
objData.AddParameter("@Name", OleDb.OleDbType.VarChar, 50, strName2)

Private Sub LoadTable()
objData.OpenConnection()
intRowsAffected = objData.Command.ExecuteNonQuery()
' Error Handling
objData.CloseConnection()
End Sub

The Access SQL command "usb_LoadImportTable" is very simple:
INSERT INTO TempTable ID, Name FROM @ID, @NAME;

I figure that I need to clear the objData settings between the various
iterations of the input record, but everything I have tried has failed.

If the code extract isn't clear, I can email the actual Notepad file.
 
Roy,

You are using complex code for a simple problem. Why don't you first try it
with direct code.
Not Stored Procedures
No parameters
etc.

If it works than you can piece by piece change it in the code it has to be
and than in the way as you did, because the principle is right.

This in the context of. It is better to learn somebody how to fish than give
him fish.

I hope this helps,

Cor
 
Roy,
OleDb parameters aren't named the way SQL parameters are. They are just
? characters and the parameters must be added to the command in the order
they appear in the SQL text.
Also the insert command would be
INSERT INTO TempTable (ID, Name) Values (?, ?);
using standard SQL syntax.
If you are using an Access Query your parameters probably have different
names than you are expecting. I think that you need to include the
enclosing square brackets in the parameter names.
You might get better answers in microsoft.public.dotnet.framework.adonet
which is dedicated to data access.

Ron Allen
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top