I have solved my problem with a deeply buried VB 2003 database book
(Database Programming with Visual Basic .NET by Carsten Thomsen) and Cor's
suggestion of using a datareader or datatable. Now...I wouldn't have known
what to look for if it wasn't for everyone that has responded to my initial
post so thanks to all. I created a new project for testing and came up with
this.
Absolutely NOTHING on the form...
THIS IS USING THE DATAREADER
Imports System.Data.OleDb
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim cnnInvMan As OleDbConnection
Dim cmmInvMan As OleDbCommand
Dim strSQL As String
Dim drdTest As OleDbDataReader
Dim field1 As String
cnnInvMan = New
OleDbConnection(My.Settings.DataReaderConnectionSt ring) 'I set this up
using the wizard by adding a new DataSource. (Access DB)
cnnInvMan.Open()
strSQL = "SELECT * FROM EMPLOYEES"
cmmInvMan = New OleDbCommand(strSQL, cnnInvMan)
drdTest = cmmInvMan.ExecuteReader
Do While drdTest.Read
field1 = drdTest.Item("FirstName") 'test my problem by
assigning it to a variable before using it in an output...
MessageBox.Show(field1) 'this shows the first name of each
employee in the Access database.
Loop
End Sub
End Class
THIS IS USING THE EXECUTESCALAR
Imports System.Data.OleDb
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim cnnInvMan As OleDbConnection
Dim cmmInvMan As OleDbCommand
Dim strSQL As String
Dim field1 As String
cnnInvMan = New
OleDbConnection(My.Settings.DataReaderConnectionSt ring)
cnnInvMan.Open()
strSQL = "SELECT FirstName FROM EMPLOYEES"
cmmInvMan = New OleDbCommand(strSQL, cnnInvMan)
field1 = cmmInvMan.ExecuteScalar().ToString
MessageBox.Show(field1)
End Sub
End Class
Thanks again to everyone!!
Tony K
"Göran Andersson" <gu***@guffa.comwrote in message
news:ey*************@TK2MSFTNGP06.phx.gbl...
Cor Ligthert [MVP] wrote:
>Tony,
If it is more than one field, then you only have the choise between a
datareader or a datatable.
Not only. Output parameters can also be used.
>It is just personal preference which you take, if you have to update them
latter however, than probably the datatable will fit the best.
Cor
"Tony K" <ki********@NOSPAMcomcast.netschreef in bericht
news:ej**************@TK2MSFTNGP02.phx.gbl...
>>Cor,
The query is not bound to say... a text box. I want the result to be
assigned to a variable so I can use it in another place in my program.
The query will always return only 1 row because the ProductIDNumber is
set to unique in the database.
How do I get the value for ProductDescription to be assigned to the
variable strProdDesc or assign the ProductID to intProdID?
Thanks,
Tony
"Cor Ligthert [MVP]" <no************@planet.nlwrote in message
news:eD*************@TK2MSFTNGP06.phx.gbl...
tony,
I am not sure of what your question is,
Do you want the first row of this exression than add Top1
If you want to make one row of this expression than add Distinct
If you only want one row to return than use the datareader,
Cor
"Tony K" <ki********@NOSPAMcomcast.netschreef in bericht
news:Ok**************@TK2MSFTNGP03.phx.gbl...
How would I assign the result of a SQL query to a variable. The
result of the following statement will ALWAYS result in 1 row
returned.
>
SELECT ProductDescription, ProductID
FROM Products
WHERE (ProductIDNumber = ?)
>
How do I assign the...say, ProductDescription to a variable called
prodDesc?
>
Thanks,
Tony
--
Göran Andersson
_____
http://www.guffa.com