Cannot fill Dataset

S

Sebastian W.

Hi,

I am still a beginner concerning ADO.net. When I am trying to read
data from a Access-file into a dataset I always fail... :-(

I am using the following code. The DB-Connection (Me.Con) is
established and open. The SQL-Code is correct and the specified table
exists.

Dim DA As New OleDbDataAdapter()
DA.SelectCommand = New OleDbCommand _
("SELECT MID, From, To, Subject FROM gmx", Me.Con)

DA.TableMappings.Add("Table", "gmx")

Dim Tbl As DataTable
Dim NR As DataRow
Dim DS As DataSet

DS = New DataSet("gmx")
DA.Fill(DS)
....

The error "An unhandled exception of type
'System.Data.OleDb.OleDbException' occurred in system.data.dll" occurs
in at the DA.Fill(DS) Command. I can do what I want. I also tried just
to fill a datatable, but I always get the same error.

What am I doing wrong?


Thanks,
Sebastian Walters
 
S

Sebastian W.

Thanks a lot. This fixed the problem with the SELECT-Clause, but now
there is a new problem:
The next few lines of the progra insert data into the table opened

Tbl = DS.Tables(0)

NR = Tbl.NewRow()
NR("MID") = "(e-mail address removed)"
NR("From") = "test
NR("To") = "test"
NR("Subject") = "test"
Tbl.Rows.Add(NR)



The Insert-Command is created by:

SQL = "INSERT INTO " & Table & "(MID, [From], To, Subject) "
SQL &= "VALUES(?, ?, ?, ?)"

Dim Cmd As New OleDbCommand(SQL, Con)
Dim P1 As OleDbParameter = New OleDbParameter("MID",
OleDbType.VarWChar, 0, "MID")
Dim P2 As OleDbParameter = New OleDbParameter("From",
OleDbType.VarWChar, 0, "From")
Dim P3 As OleDbParameter = New OleDbParameter("To",
OleDbType.VarWChar, 0, "To")
Dim P4 As OleDbParameter = New OleDbParameter("Subject",
OleDbType.VarWChar, 0, "Subject")

Cmd.Parameters.Add(P1)
Cmd.Parameters.Add(P2)
Cmd.Parameters.Add(P3)
Cmd.Parameters.Add(P4)

DA.insertCommand=cmd

DA.Update(Tbl)

And at the Point at which I want to update the DA I get a 'An
unhandled exception of type 'System.Data.OleDb.OleDbException'
occurred in system.data.dll' again...

Please help me

Thanks a lot,
Sebastian Walters
 

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

Top