Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > referencing a record from a MySQL table

Reply
Thread Tools

referencing a record from a MySQL table

 
 
TheDude5B
Guest
Posts: n/a
 
      10-24-2005
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

 
Reply With Quote
 
 
 
 
Leon Mayne [MVP]
Guest
Posts: n/a
 
      10-24-2005
TheDude5B wrote:
> 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?


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.


 
Reply With Quote
 
 
 
 
Hans Kesting
Guest
Posts: n/a
 
      10-24-2005
> 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()


 
Reply With Quote
 
TheDude5B
Guest
Posts: n/a
 
      10-24-2005
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

 
Reply With Quote
 
TheDude5B
Guest
Posts: n/a
 
      10-25-2005
..

 
Reply With Quote
 
Leon Mayne [MVP]
Guest
Posts: n/a
 
      10-25-2005
TheDude5B wrote:
> 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


 
Reply With Quote
 
TheDude5B
Guest
Posts: n/a
 
      10-25-2005
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

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
You cannot add or change a record because a related record is required in table 'lok" André ASP .Net 0 06-25-2006 01:30 PM
You cannot add or change a record because a related record is required in table 'lok" André ASP .Net Web Controls 0 06-25-2006 01:30 PM
using mysql client to read a file to create a table in a database in a mysql server julian Ruby 8 04-06-2006 10:29 AM
Retrieving Record Key while creating the record. =?Utf-8?B?SnVzdGlu?= ASP .Net 4 10-05-2004 08:11 PM
" Invalid Disk Table in Boot Record - Boot Record could not be repaired " reply@newsgroup.please Computer Support 2 12-01-2003 05:37 AM



Advertisments