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

Recommended Answers

All 4 Replies

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

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.

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()

`

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.