Click to See Complete Forum and Search --> : Simple select of an array in vb.net


rbailer
04-27-2006, 12:14 AM
I am having trouble with a select query in that if I select all of the data from a row, i cant figure out how to get one specific part of the array of data. In this querry right now, the query returns the value from the first column. How can i access the values from the 2nd, 3rd columns, etc.

'create a connection object
Dim cn As New OleDb.OleDbConnection

'create a command
Dim cmd As New OleDb.OleDbCommand

'create a command text
Dim cText As String

'build the sql insert statement
cText = "SELECT * FROM AboutMe WHERE id = '1'"

'set the connection string for the database
cn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & MapPath("database.mdb")

'set the connection for the command
cmd.Connection = cn

'set the command type
cmd.CommandType = CommandType.Text

'set the command text
cmd.CommandText = cText

'open the connection
cn.Open()
'run the command
cmd.ExecuteNonQuery()

Dim Result As String
Result = cmd.ExecuteScalar()
Me.caption.Text = Result.ToString()
'close the connection
cn.Close()

rbailer
04-27-2006, 11:09 AM
I figured this out. A Scalar only selects the value at (0,0). You need to use a datareader in order to select more data.