VB 08 sql server database login form

using a column made in the data set designer

Page 1 of 1

5 Replies - 17091 Views - Last Post: 03 April 2009 - 07:36 AM Rate Topic: -----

#1 bored4  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 15
  • Joined: 01-May 08

VB 08 sql server database login form

Post icon  Posted 01 April 2009 - 05:19 AM

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")
		conn.Open()

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

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

		If conn.State <> ConnectionState.Closed Then
			conn.Close()
		End If

		Dim form As New Form1
		form.Show()

	End Sub

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

	Private Sub EmployeeBindingNavigatorSaveItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles EmployeeBindingNavigatorSaveItem.Click
		Me.Validate()
		Me.EmployeeBindingSource.EndEdit()
		Me.TableAdapterManager.UpdateAll(Me.PubsLoginDataSet)

	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.
		Me.EmployeeTableAdapter.Fill(Me.PubsLoginDataSet.employee)

	End Sub
End Class 

This post has been edited by bored4: 02 April 2009 - 04:55 AM


Is This A Good Question/Topic? 0
  • +

Replies To: VB 08 sql server database login form

#2 bored4  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 15
  • Joined: 01-May 08

Re: VB 08 sql server database login form

Posted 02 April 2009 - 04:57 AM

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.

This post has been edited by bored4: 02 April 2009 - 05:18 AM

Was This Post Helpful? 0
  • +
  • -

#3 Arazons  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 1
  • View blog
  • Posts: 79
  • Joined: 18-March 09

Re: VB 08 sql server database login form

Posted 02 April 2009 - 01:26 PM

View Postbored4, on 2 Apr, 2009 - 03:57 AM, said:

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.


You can always reference columns by index or ordinal instead of column name...

As far as looking in a datatable for anything use the dattables find method.

This post has been edited by Arazons: 02 April 2009 - 01:28 PM

Was This Post Helpful? 0
  • +
  • -

#4 bored4  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 15
  • Joined: 01-May 08

Re: VB 08 sql server database login form

Posted 03 April 2009 - 01:30 AM

I don't think i can do that though. Because the username column only exists in the dataset and not the actual database and when i run the query it queries the database where there is no username column. But i can't seem to find any information on running a query on the dataset where username column is, if its even possible to run a query against the dataset.

This post has been edited by bored4: 03 April 2009 - 01:45 AM

Was This Post Helpful? 0
  • +
  • -

#5 searockruz  Icon User is offline

  • D.I.C Regular

Reputation: 24
  • View blog
  • Posts: 460
  • Joined: 07-March 09

Re: VB 08 sql server database login form

Posted 03 April 2009 - 01:45 AM

how about using simple code

Dim con as new SqlConnection("connectionstaing")
Dim ds as new DataSet()
Dim dt as New DataTable()

Dim adapter as new SqlDataAdapter("Your Query",con)
adapter.Fill(ds)
dt=ds.Tables("tablename")

if dr.Rows.Count >0 then
'Authenticated
else
'go away
end if
Was This Post Helpful? 0
  • +
  • -

#6 bored4  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 15
  • Joined: 01-May 08

Re: VB 08 sql server database login form

Posted 03 April 2009 - 07:36 AM

Thanks for the replies.

Same error at adapter.fill(ds)
"Invalid column name 'username'. Invalid column name 'username' "
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1