Wrox Programmer Forums
|
VB.NET 2002/2003 Basics For coders who are new to Visual Basic, working in .NET versions 2002 or 2003 (1.0 and 1.1).
Welcome to the p2p.wrox.com Forums.

You are currently viewing the VB.NET 2002/2003 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old May 4th, 2005, 07:40 AM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

I made a few changes to your function. This is how I'd do it:

Function MAINquery(ByVal board As String, ByVal chassis As String, ByVal hDDType As String) As System.Data.DataSet
     Dim connectionString As String = "Provider=Microsoft.Jet.OLEDB.4.0; Ole DB Services=-4; Data Source=C:\Documents an"& _
"d Settings\Desktop\FinSample.mdb"
     Dim dbConnection As New System.Data.OleDb.OleDbConnection(connectionString )

     Dim queryString As String = "SELECT [System].* FROM [System] WHERE (([System].[Board] = ?) AND ([System]."& _
"[Chassis] = ?) AND ([System].[HDDType] = ?))"
     Dim dbCommand As New System.Data.OleDb.OleDbCommand
     dbCommand.CommandText = queryString
     dbCommand.Connection = dbConnection

     dbCommand.Parameters.Add("@Board", System.Data.DbType.String).Value = board
     dbCommand.Parameters.Add("@Chassis", System.Data.DbType.String).Value = chassis
     dbCommand.Parameters.Add("@HDDType", System.Data.DbType.String).Value = hDDType

     Dim dataAdapter As New System.Data.OleDb.OleDbDataAdapter
     dataAdapter.SelectCommand = dbCommand
     Dim dataSet As New System.Data.DataSet
     dataAdapter.Fill(dataSet)

     Return dataSet
 End Function

-Peter
 
Old May 4th, 2005, 07:42 AM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

Note the name of the parameters is mostly irrelevant in the above case. What's important is the ORDER. They must be added to the parameters collection in the same order they are used in the command text.

-Peter
 
Old May 4th, 2005, 07:56 AM
Authorized User
 
Join Date: Apr 2005
Posts: 73
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Peter and Prashant, thank you guys so much, I honestly don't know what I'd do, you have both helped me to get the query working as perfect as it could.

Thank You.

D

 
Old May 4th, 2005, 11:21 PM
Friend of Wrox
 
Join Date: Apr 2005
Posts: 186
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I create the same table in access the same row and bound it to a datagrid , i am getting the row perfectly,
This leaves me with only one clue,

Your DB Path is:

C:\Documents an"& _
"d Settings\Desktop\FinSample.mdb

But usually the all paths to Desktop I have seen will be something like like
"C:\Documents and Settings\Administrator\Desktop"
Ie, you have the Loggedin user Administrator before the Desktop

I may not be correct, but please do ensure that you are using the same db, because you might be checking the db on your desktop through access, and the program will be working on another. It happens sometimes...

regards
Prashant





Similar Threads
Thread Thread Starter Forum Replies Last Post
Running an Access Query from ASP arholly Access ASP 0 January 25th, 2008 03:31 PM
Running query... Question... RinoDM SQL Server 2000 2 July 26th, 2007 08:49 AM
Running a Query anukagni Access 3 May 5th, 2006 12:16 AM
running out of field in query building yixchen Access 2 December 19th, 2005 10:19 AM
Running an SQL query in VBA... Augusta Access VBA 3 December 1st, 2004 05:17 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.