OleDbDataAdapter

Simon4VB

Member
Joined
Apr 2, 2009
Messages
23
Programming Experience
1-3
Hi
I was asked what 2 items of information are needed to configure an instance of an OleDbDataAdapter, what was it referred to.
any help please.
 
That question is rather vague. To be precise, an OleDbDataAdapter needs exactly one thing to be useful: an OleDbCommand. How exactly that OleDbCommand gets created and used depends on the situation. The simplest way is like this:
VB.NET:
Dim adapter As New OleDbDataAdapter("SQL query here", "connection string here")
I would guess that those are the two items of information the question is referring to but that is not the only way to create a data adapter.
 
Thanks for your reply.
Is this

Dim adapter As New OleDbDataAdapter("SQL query here", "connection string here")

The same as;
Dim strPath As String(connection) or (SQL statement)
 
I don't really understand the question. My example implied that you pass two strings to the constructor: one containing the SQL query you want to execute and the other containing the connection string for your database. Like I said, what an OleDbDataAdapter really needs is an OleDbCommand, which itself needs an OleDbConnection. My previous example will implicitly create them both but you can take responsibility for creating the connection yourself:
VB.NET:
Dim connection As New OleDbConnection("connection string here")
Dim adapter As New OleDbDataAdapter("SQL query here", connection)
or even both:
VB.NET:
Dim connection As New OleDbConnection("connection string here")
Dim command As New OleDbCommand("SQL query here", connection)
Dim adapter As New OleDbDataAdapter(command)
 
Just to check if I got it right, they go something like this?

Dim connection As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0"&"DataSource=D:\somedb.mdb")

and

Dim command As New OleDbCommand("SELECT* FROM somedb")
 
Just to check if I got it right, they go something like this?

Dim connection As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0"&"DataSource=D:\somedb.mdb")

Why do people split strings up like this, but with nothing in between? I've never understood why people will write:

Dim str as String = "hel" & "lo" & " " & "worl" & "d"

When they could just write:

Dim str as String = "hello world"


It always sticks out like a sore thumb to me, when someone has concatenated two fixed strings together..

Had you had them joined as one, it would be more obvious that you're missing a rather vital semi-colon..


Dim command As New OleDbCommand("SELECT* FROM somedb")
[/quote]
Only if your table name is the same as your database name.. ;)
 
Back
Top