i have an assignment, yes im a student, and i need to make a login screen that reads values from a sql database. My problem is that im failing miserably. I have visual studio 2010 and SQL server 2008 R2. I have watched videos on youtube but i ran into issues, i did almost exactly what the example in my book has, failed at it, so i figured when all else fails, go get help from the fellow coders plus i want to do something like this just for a fun summer project too so i really would like to learn this. Any how, i will attach the sql script for the database so anyone can take a look if that helps. Here is the current code i have, which gives me an error at runtime saying "Invalid object 'SportEmployee'".
Imports System.Data.SqlClient Public Class LoginForm Dim cnEmployee As New Data.SqlClient.SqlConnection Dim daEmployee As New Data.SqlClient.SqlDataAdapter Dim sqlCommand As New Data.SqlClient.SqlCommand Dim dsEmployee As New Data.DataSet Dim db As New SportMotorsDataSet Private Sub LoginForm_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing frmMenu.Show() End Sub Private Sub LoginForm_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load frmMenu.Hide() End Sub Private Sub LoginBtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles LoginBtn.Click 'connection string cnEmployee.ConnectionString = "Data Source=.\SQLEXPRESS;Initial Catalog=EBD;Integrated Security=True" sqlCommand.CommandText = "Select * " & _ "From [SportEmployee] " & _ "Where EmployeeUsername= '" & UserNameTextBox.Text & _ "'AND EmployeePassword= '" & PasswordTextBox.Text & "';" cnEmployee.Open() sqlCommand.Connection = cnEmployee daEmployee.SelectCommand = sqlCommand daEmployee.Fill(dsEmployee) 'Error highlights this Dim count = dsEmployee.Tables(0).Rows.Count If count > 0 Then MsgBox("You have successfully logged in") Else MsgBox("You suck at life", MsgBoxStyle.Critical) UserNameTextBox.Clear() PasswordTextBox.Clear() UserNameTextBox.Focus() End If End Sub End Class
Can anyone explain what the problem is here? I saw a lot of different ways of doing this but none worked right for me.I appreciate the help all.
Number of downloads: 938