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

VB05 Newbie: How to access a datasets data 1

Status
Not open for further replies.

marskills

Programmer
Oct 14, 2007
7
CA
Hello all,

I'm a vb6 programmer who has finally committed to move to .Net and I'm starting my first project. I'm using VB 2005 and mySQL for the database. I've so far been able to load data into a datatable or dataset but I don't know how to access the data in it. In vb6 I would use the .fields("fieldname") on a recordset. I have two questions:

1) If I'm retrieving data from a table and want to manually play with it should I use a dataset or datatable to load the data into?

2) For both a dataset and a datatable, how do I reference the field contents of a record?

Any guidance or reference would be really appreciated.

Here is what I have so far:

Imports MySql.Data.MySqlClient
Imports System.Data

Public Class frmLogin

Dim conn As New MySqlConnection
Dim myCommand As New MySqlCommand
Dim myAdapter As New MySqlDataAdapter
Dim myDataSet As New DataSet
Dim strSQL As String
Dim myConnString As String
'Open the Database
Try
'conn = New MySqlConnection

myConnString = "server=localhost; user id=user; password=pw; database=mydatabase"
conn.ConnectionString = myConnString

strSQL = "SELECT * FROM Security WHERE loginID ='" & txtUserName.Text & "'"
myCommand.CommandText = strSQL
myAdapter.SelectCommand = myCommand
myAdapter.SelectCommand.Connection = conn
myAdapter.Fill(myDataSet)
conn.Close()


If Not myDataSet.WHAT GOES HERE? = txtPassword.Text Then ...

Thanks.
 
1. to retrieve data only use datareader
to save use dataset

for datareader

Dim oleDrd As OleDbDataReader
Dim oleCmd As New OleDbCommand

oleCmd.CommandText = sql
oleDrd = .ExecuteReader
oledrd.read
variable = .item(fieldname)

for dataset

you still need a datarow

Dim oleDrw As DataRow
oleDrw = oleDst.Tables(0).rows(rownumber)

If Not oleDrw.item(fieldname) = txtPassword.Text Then ...
OR
If Not oleDrw!fieldname = txtPassword.Text Then ...
 
Thank you Maytel. That does clear things up.

Kind regards,

Rory
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top