i'm trying to make a login form connected to an sql server database. my data base has records like this:

fname - lname - minit

each name in a separate column, and i wanted to use the name as the login username, so in the dataset designer i made a new column and concatenated the names together like this: lname+fname+minit

but at Dim dr As SqlDataReader = cmd.ExecuteReader i get this error:

"Invalid column name 'username'. Invalid column name 'username'."

i'm asuming that's because username doesn't actually exists in the database, only in the dataset.

is there a way to get that to work with out the username column actually existing in the database?

Imports System.Data.SqlClient

Public Class LoginForm

    Private Sub OK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OK.Click
        Dim cmd As SqlCommand
        Dim conn As SqlConnection

        Dim sql = "SELECT username,emp_id FROM employee WHERE username = '" & UsernameTextBox.Text & "' AND emp_id = '" & PasswordTextBox.Text & "'"

        conn = New SqlConnection("Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Pubs.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True")

        cmd = New SqlCommand(sql, conn)
        Dim dr As SqlDataReader = cmd.ExecuteReader

            If dr.Read = False Then
                MessageBox.Show("Authentication Failed...")
                MessageBox.Show("Login Successful...")
            End If
        Catch ex As Exception
        End Try

        If conn.State <> ConnectionState.Closed Then
        End If

        Dim form As New Form1

    End Sub

    Private Sub Cancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Cancel.Click
    End Sub

    Private Sub EmployeeBindingNavigatorSaveItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles EmployeeBindingNavigatorSaveItem.Click

    End Sub

    Private Sub LoginForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'TODO: This line of code loads data into the 'PubsLoginDataSet.employee' table. You can move, or remove it, as needed.

    End Sub
End Class

Ok after staring at this i realized i'm querying the database correct? but what i need to do it query the dataset instead? hmmm i'm not sure how to change my code to do that.

i think we have the same problem, what i have noticed in my code is that what the user inserted in my username textbox will be generated in the error like for example the user inserted "billGates" as username the error will look like "Invalid Column name billGates". whats wrong with this?

thanks this works

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.