Creating Logon screen with SQL Connection
-
I have just started creating a new vb application which requires a login screen. I have created a new database in sql server 2000 which holds the usernames and passwords. I was wondering how i would create the connection and then link the username and password text boxes to the fields in the database. Regards. David
-
I have just started creating a new vb application which requires a login screen. I have created a new database in sql server 2000 which holds the usernames and passwords. I was wondering how i would create the connection and then link the username and password text boxes to the fields in the database. Regards. David
-
Do you have any code to show what you've attempted thus far?
Any suggestions, ideas, or 'constructive criticism' are always welcome. "There's no such thing as a stupid question, only stupid people." - Mr. Garrison
Public Class Private sqlConn AS SQLConnection = New Sql Connection (connectionstring) Private sub LoginScript() SqlConn.open DIM SqlCmd AS New SQLCommand = (StoredProcdure, SqlConn) Dim SqlAdapter as sqldataadapter = new sqlAdapter(sqlCmd) Dim dt as new DataTable SqlAdapter.fill(dt) IF dt.select("username = " +txtUserName.text + "AND password = " + txtPassword.text) > 0 THEN 'login Else msgbox("Login Failed", "Login Failed", vbOK) END IF END sub
-
Public Class Private sqlConn AS SQLConnection = New Sql Connection (connectionstring) Private sub LoginScript() SqlConn.open DIM SqlCmd AS New SQLCommand = (StoredProcdure, SqlConn) Dim SqlAdapter as sqldataadapter = new sqlAdapter(sqlCmd) Dim dt as new DataTable SqlAdapter.fill(dt) IF dt.select("username = " +txtUserName.text + "AND password = " + txtPassword.text) > 0 THEN 'login Else msgbox("Login Failed", "Login Failed", vbOK) END IF END sub
I would highly recommend picking up a book on VB.NET and SQL Server and working through them before taking this project on. The code you're written so far is terrible and if you continue to use the techniques you've demonstrated so far, your project is going to fail miserably. Amazon results[^]
A guide to posting questions on CodeProject[^]
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007, 2008 -
I would highly recommend picking up a book on VB.NET and SQL Server and working through them before taking this project on. The code you're written so far is terrible and if you continue to use the techniques you've demonstrated so far, your project is going to fail miserably. Amazon results[^]
A guide to posting questions on CodeProject[^]
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007, 2008I have recently read a VB book, as you can imagine, i am a complete novice when it comes to vb and programming. I have written this piece of code. I was wondering if you could tell me if this would create a valid connection or not. Imports System Imports System.Data Imports System.Data.SqlClient Public Class frmLogin Public sqlconnection As SqlConnection = New SqlConnection("Data Source=TG-IT-TPSRV;Initial Catalog=AFQ;User ID=sa;Password=;") Public Sub frmLogin() Dim sqlConn As SqlConnection = sqlconnection Dim sqlComm As String = ("SELECT * FROM Users") End Sub Private Sub BtnCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCancel.Click Me.Close() End Sub Public Sub Logon_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load End Sub Private Sub BtnOK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOK.Click Dim sConnectionString As String = "Source=TG-IT-TPSRV;Initial Catalog=AFQ;User ID=sa;Password=;" Dim objConn As New SqlConnection(sConnectionString) Dim sqlComm As String = ("SELECT * FROM Users") Dim objComm As New SqlCommand(sqlComm, sqlconnection) objConn.Open() End Sub End Class
-
I have recently read a VB book, as you can imagine, i am a complete novice when it comes to vb and programming. I have written this piece of code. I was wondering if you could tell me if this would create a valid connection or not. Imports System Imports System.Data Imports System.Data.SqlClient Public Class frmLogin Public sqlconnection As SqlConnection = New SqlConnection("Data Source=TG-IT-TPSRV;Initial Catalog=AFQ;User ID=sa;Password=;") Public Sub frmLogin() Dim sqlConn As SqlConnection = sqlconnection Dim sqlComm As String = ("SELECT * FROM Users") End Sub Private Sub BtnCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCancel.Click Me.Close() End Sub Public Sub Logon_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load End Sub Private Sub BtnOK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOK.Click Dim sConnectionString As String = "Source=TG-IT-TPSRV;Initial Catalog=AFQ;User ID=sa;Password=;" Dim objConn As New SqlConnection(sConnectionString) Dim sqlComm As String = ("SELECT * FROM Users") Dim objComm As New SqlCommand(sqlComm, sqlconnection) objConn.Open() End Sub End Class
Yeah, it would create a connection, but your design is going to cause you problems down the road.
A guide to posting questions on CodeProject[^]
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007, 2008