BD with access y reference your fields

  • Thread starter Thread starter nahald
  • Start date Start date
N

nahald

hello,
I have a problem to a database (Access) and I reference its fields
before in Vb 6, I am do this with:

Dim RS As Recordset
Nombre_BD = "SERVICIOS.MDB"
Set ConexionBD = OpenDatabase(App.Path & "\" & Nombre_BD)
Set RS = ConexionBD.OpenRecordset("Select * from tabla")
RS.Fields("companyiaParte")

In visual basic .net, what am I do??

Thanks
nahald
 
Hi Nahald,

Something as this
\\\
Dim Conn As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;" & "Data
Source=C:\SERVICIOS.MDB;" )
Try
Dim cmd As New OleDbCommand("Select * from tabla", Conn)
da = New OleDbDataAdapter(cmd)
da.Fill(ds, "tabla")
Catch oledbExc As OleDbException
MessageBox.Show(oledbExc.ToString)
Catch ex As Exception
MessageBox.Show(ex.Message)
Finally
Conn.Close()
End Try
The item from the first row is
dim a as string = ds.tables("tabla").rows(0).item("companyiaParte").tostring
///

I hope this was what you where looking for?

Cor
 
Hi Nahald,

Good you showed me I forgot that row

Now it is between the text

Sorry.

Cor
Sorry, but You don´t defined ds than a variable, What is "ds"?

dim ds as new Dataset
 
ok, thanks I think this line.
If I have to do a insert, update o delete in database, I will change this
line:

Dim cmd As New OleDbCommand("Select * from tabla", Conn)

Is this true?

nahald
 
Nahald,

Yes and than add them to the dataAdapter with
da.DeleteCommand = cmd (to do for the insertcommand, the deletecommand and
the updatecommand)

But for an update for a select as you are using it is more simple to add
after the
Dim cb As New OleDbCommandBuilder(da)
(that makes and add the update, delete and insert for you, but they said it
is buggy with a lot of parameters).

When you have done that you can do to update
\\\
if ds.haschanges
da.update(ds.getchanges)
end if
///

Cor
 
Thanks for all
I will test this.
nahald

Cor said:
Nahald,

Yes and than add them to the dataAdapter with
da.DeleteCommand = cmd (to do for the insertcommand, the deletecommand and
the updatecommand)

But for an update for a select as you are using it is more simple to add
after the

Dim cb As New OleDbCommandBuilder(da)
(that makes and add the update, delete and insert for you, but they said it
is buggy with a lot of parameters).

When you have done that you can do to update
\\\
if ds.haschanges
da.update(ds.getchanges)
end if
///

Cor
OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;"
 
Back
Top