referencing a record from a MySQL table

T

TheDude5B

Hi, i dont know if this is the best place to post this, if there is a
better forum could you let me know.

My problem: i am new to asp.net and am using a MySQL database to hold
my information. I have the code:
*******************************************************************
Dim myConnection As MySqlConnection
Dim myDataAdapter As MySqlDataAdapter
Dim myDataSet As DataSet

Dim strSQL As String
Dim iRecordCount As Integer

myConnection = New MySqlConnection("server=mysever; user id=myid;
password=mypassword; database=mydatabase; pooling=false;")

strSQL = "SELECT * FROM xbmembers;"

myDataAdapter = New MySqlDataAdapter(strSQL, myConnection)
myDataSet = New Dataset()
myDataAdapter.Fill(myDataSet, "xbmembers")
*******************************************************************

I would like to be able to reference a single record from this table.
i.e. In asp i would have written
-----------------------------------------------------
WHILE NOT adoRS.EOF
IF UserName = adoRS("member_username") THEN
do something
END IF

adoRS.MoveNext
WEND
-----------------------------------------------------

What is the best way in which i could do this using asp.net accessing a
MySQL database?

Thanks Tim James
 
L

Leon Mayne [MVP]

TheDude5B said:
Hi, i dont know if this is the best place to post this, if there is a
better forum could you let me know.

My problem: i am new to asp.net and am using a MySQL database to hold
my information. I have the code:
*******************************************************************
Dim myConnection As MySqlConnection
Dim myDataAdapter As MySqlDataAdapter
Dim myDataSet As DataSet

Dim strSQL As String
Dim iRecordCount As Integer

myConnection = New MySqlConnection("server=mysever; user id=myid;
password=mypassword; database=mydatabase; pooling=false;")

strSQL = "SELECT * FROM xbmembers;"

myDataAdapter = New MySqlDataAdapter(strSQL, myConnection)
myDataSet = New Dataset()
myDataAdapter.Fill(myDataSet, "xbmembers")
*******************************************************************

I would like to be able to reference a single record from this table.
i.e. In asp i would have written
-----------------------------------------------------
WHILE NOT adoRS.EOF
IF UserName = adoRS("member_username") THEN
do something
END IF

adoRS.MoveNext
WEND

Which DBMS you use shouldn't make a difference. Try this:

DataTable dt = ds.Tables["xbmembers"];
foreach (DataRow dr in dt)
{
if(!dr["member_username"].Equals(""))
{
//Do something
}
}

That's in C# though, I can translate it into VB if you need it.
 
H

Hans Kesting

Hi, i dont know if this is the best place to post this, if there is a
better forum could you let me know.

My problem: i am new to asp.net and am using a MySQL database to hold
my information. I have the code:
*******************************************************************
Dim myConnection As MySqlConnection
Dim myDataAdapter As MySqlDataAdapter
Dim myDataSet As DataSet

Dim strSQL As String
Dim iRecordCount As Integer

myConnection = New MySqlConnection("server=mysever; user id=myid;
password=mypassword; database=mydatabase; pooling=false;")

strSQL = "SELECT * FROM xbmembers;"

myDataAdapter = New MySqlDataAdapter(strSQL, myConnection)
myDataSet = New Dataset()
myDataAdapter.Fill(myDataSet, "xbmembers")
*******************************************************************

I would like to be able to reference a single record from this table.
i.e. In asp i would have written
-----------------------------------------------------
WHILE NOT adoRS.EOF
IF UserName = adoRS("member_username") THEN
do something
END IF

adoRS.MoveNext
WEND
-----------------------------------------------------

What is the best way in which i could do this using asp.net accessing a
MySQL database?

Thanks Tim James

myDataSet.Tables[0].Rows[0]["member_username"].ToString()
 
T

TheDude5B

Thanks, would you be able to translate it into VB please?
I should really start doing asp.net in C# as all the tutorials and
examples i find are all in C#

Thanks
 
L

Leon Mayne [MVP]

TheDude5B said:
Thanks, would you be able to translate it into VB please?
I should really start doing asp.net in C# as all the tutorials and
examples i find are all in C#

OK, I /think/ this should work:

Dim dt As DataTable = ds.Tables("xbmembers")
For Each dr As DataRow In dt.Rows
If (dr("member_username") <> "") Then
' Do something
End If
Next
 
T

TheDude5B

Thats great thanks,

got everything working now. found some good information in the MSDN
library to so going to have a good read through all the pages there.

Thanks Again!
Tim
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,066
Latest member
VytoKetoReviews

Latest Threads

Top