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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

OleDbDataAdapter: SELECT with field list?

Status
Not open for further replies.

AdaHacker

Programmer
Sep 6, 2001
392
US
Forgive me if this is obvious, but I'm still getting used to ADO.NET and it is a Monday morning.

I'm making a simple form to display data from an Access database. The relevant code looks like this:
Code:
Dim conn As OleDb.OleDbConnection
Dim da As OleDb.OleDbDataAdapter
Dim ds As DataSet
Dim conn_str As String
Dim default_cmd_text As String

conn_str = "Provider=Microsoft.Jet.OLEDB.4.0; Persist Security Info=False; Data Source=C:\mydb.mdb"
conn = New OleDb.OleDbConnection(conn_str)

default_cmd_text = "select rate_code, basic_rate, supplies, usage from equipment_rates"
da = New OleDb.OleDbDataAdapter(default_cmd_text, conn)
ds = New DataSet()
da.Fill(ds, "rate_codes")
When I run the above code, it throws an OleDbException on the last line. However, if I change default_cmd_text to "select * from equipment_rates", then it works.

What am I missing here? The examples I've seen led me to believe that you could pass the Data Adapter an arbitrary SELECT query. Is that not the case?
 
in default_cmd_txt, you reference rate_code, but the last line references rate_code[red]s[/red]

-George

Strong and bitter words indicate a weak cause. - Fortune cookie wisdom
 
Thanks for the replies!

I've figured it out. It wasn't a typo.

I did a little experimenting and it worked when I remove the "usage" field. A little Googling revealed that "usage" is a reserved word in Transact-SQL (which, I presume, is the dialect ADO.NET is using). Apparently it isn't in the dialect used by Access 97 (don't ask why we're still using Office 97), which is why it didn't show up when I tried the query in Access. Anyway, everything is fine if I bracket that field in the query, e.g.
Code:
select rate_code, basic_rate, supplies, [usage] from equipment_rates
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top