0
 imports system.data.sqlclient
 mysqlconn = New SqlConnection
        mysqlconn.ConnectionString = "Data Source=" + txtServerName.Text + ";initial catalog=" + txtdatabasename.Text + ";initial catalog=" + txtshardacc.Text + ";user id=" + textusername.Text + ";password=" + txtpassword.Text
        Dim queryresult As Integer




        Try


            mysqlconn.Open()
            command = New SqlCommand("select COUNT (*) as numRows from _Char Where CharName16='" & TextBox40.Text & "'", mysqlconn)
            queryresult = command.ExecuteScalar
            mysqlconn.Close()


            If queryresult = 0 Then
                MsgBox("charactername not found ", MsgBoxStyle.Critical, "Error")
            Else
                MsgBox("(1) Username Found " & TextBox40.Text, MsgBoxStyle.Information, "Done")
                TextBox29.Enabled = True
                TextBox30.Enabled = True
                TextBox31.Enabled = True
                TextBox32.Enabled = True
                TextBox32.Enabled = True
                TextBox33.Enabled = True
                TextBox34.Enabled = True
                TextBox35.Enabled = True
                TextBox36.Enabled = True
                TextBox37.Enabled = True
                TextBox38.Enabled = True
                TextBox39.Enabled = True
                Try
                    mysqlconn.Open()
                    Dim reader As SqlDataReader

                    reader = command.ExecuteReader
                    If reader.HasRows Then
                        TextBox39.text = reader.Item("Curlevel")
                    End If

                Catch ex As Exception
                    MessageBox.Show(ex.Message)
                End Try


            End If
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try
    End Sub

Edited by Abdelaziz_1

3
Contributors
4
Replies
15
Views
10 Months
Discussion Span
Last Post by Shark_1
0

I need the program show data from database called _Char of column called CurLevel to textbox

0

Since this is vb.net the visual studio lets you single step it to find out what line is failing. Dumping code is rarely helpful.

0
mysqlconn.Open()
Dim reader As SqlDataReader
reader = command.ExecuteReader
If reader.HasRows Then
    TextBox39.text = reader.Item("Curlevel")
End If

You did a simple mistake in between the above lines.
command = New SqlCommand("select COUNT (*) as numRows from _Char Where CharName16='" & TextBox40.Text & "'", mysqlconn) returns you the number of rows but not the field values.
To get values you must have to create a new sql query statement and read records from datareader.
Your codes would be

mysqlconn.Open()
command = New SqlCommand("select * from _Char Where CharName16='" & TextBox40.Text & "'", mysqlconn)
Dim reader As SqlDataReader
reader = command.ExecuteReader()
If reader.HasRows Then
    reader.Read()
    TextBox39.text = reader.Item("Curlevel")
End If
mysqlconn.Close()

`

This article has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.