On Mon, 21 Jun 2004 07:18:02 -0700, Art <Ar*@discussions.microsoft.com> wrote:
¤ Hi,
¤
¤ Can anyone point me to an example of how I would execute a query I've created in an Access DB. I've copied the SQL down to my VB.net application and that works fine, but it's ugly. I'd like to direcly execute the query that I created in Access - if possible.
¤
¤ Also, I would like to be able to add a parameter to that query. For example, if I'm in Access and put an unknown field in the query, I get prompted to enter that info when the query runs. I'm hoping that can also be done through VB.net.
¤
¤ Art
Here is an example of how to execute an Access QueryDef and place the contents of the Select query
into a DataSet:
Dim AccessConn As System.Data.OleDb.OleDbConnection
AccessConn = New System.Data.OleDb.OleDbConnection("Provider=Micros oft.Jet.OLEDB.4.0;" & _
"Data Source=e:\My Documents\db1.mdb")
AccessConn.Open()
Dim AccessCommand As New System.Data.OleDb.OleDbCommand("qryTable1", AccessConn)
AccessCommand.CommandType = CommandType.StoredProcedure
AccessCommand.Parameters.Add("@ParamName", System.Data.OleDb.OleDbType.VarWChar).Value =
"SomeValue"
Dim da As OleDb.OleDbDataAdapter = New OleDb.OleDbDataAdapter
With da
.SelectCommand = AccessCommand
End With
Dim ds As New DataSet("QueryTables")
da.Fill(ds, "Table1")
Paul ~~~
pc******@ameritech.net
Microsoft MVP (Visual Basic)