i wonder why my code have an error.. this my code and i will highlight the error

.. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        Dim connection As New SqlClient.SqlConnection
        Dim command As New SqlClient.SqlCommand
        Dim adapter As New SqlClient.SqlDataAdapter
        Dim dataset As New DataSet

        connection.ConnectionString = ("Data Source=CUBED-DESKTOP05;Initial Catalog=Biometrics;Integrated Security=True")

        connection.Open()


        command.CommandText = " SELECT * FROM (admin) WHERE username= '" & TextBox1.Text & "' AND password= '" & TextBox2.Text & "';"

        

        command.Connection = connection

        adapter.SelectCommand = command
        
' this part is where the error made
adapter.Fill(dataset, "0")

        Dim count = dataset.Tables(0).Rows.Count

        If count > 0 Then
            MsgBox("Welcome to Cubed Technologies", MsgBoxStyle.OkOnly)
            Form2.Show()
            Me.Close()
        Else
            MsgBox("Incorrect Login please Check your Username and Password")
            TextBox1.Clear()
            TextBox2.Clear()
            Me.TextBox1.Focus()

        End If

    End Sub

Recommended Answers

What exactly is the error message ?

Why the table name is within parenthesis ?

NOTE:--Do not use dataset as name of an object, it is a predefined key word..

Jump to Post

All 2 Replies

What exactly is the error message ?

Why the table name is within parenthesis ?

NOTE:--Do not use dataset as name of an object, it is a predefined key word..

commented: error stated -1
commented: Erase -ve rep +15

Dont complicate things. Do it like this:

Dim conn As New SqlConnection("connString")
Dim da As New SqlDataAdapter()
Dim table As New DataTable()
da.SelectCommand.CommandText = "your select query"
da.SelectCommand.Connection = conn
da.Fill(table)

And you dont have to use DataSet,if you only have one DataTable. Instead you use DataTable, as I showed in example.

Be a part of the DaniWeb community

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