Kraxed
Kraxed

Reputation: 350

Convert MySQL DataSet to String

I want to check if a user is an administrator or user and I want to change the dataset to a string so I can use it in Label1.

I've tried Using 'GetXML' but it comes in a funny format something like 'Administrator', well it's a bit different to that. I want to be able to use the value of the label1.text for other features in my program.

Here is my code:

    Dim SQLConnection As MySqlConnection = New MySqlConnection
    Dim ServerString As String = "server=localhost;user id=root;password=;database=business elements"
    SQLConnection.ConnectionString = ServerString
    SQLConnection.Open()

    Dim ds As New DataSet()
    Dim cmd As New MySqlCommand("SELECT Level FROM users WHERE username = '" & UsernameTextBox.Text & "'", SQLConnection)
    Dim da As New MySqlDataAdapter(cmd)
    da.Fill(ds)
    Dim str As String = ds.GetXml
    ds.GetXml()
    Label1.Text = str

Upvotes: 0

Views: 3716

Answers (1)

ijason03
ijason03

Reputation: 581

Try this

Dim str As String = ds.Tables(0).Rows(0).Item(0).ToString()

Upvotes: 1

Related Questions