EDN Admin
Well-known member
H
i, I need to define sql command to retieve user name, password and balance from database.. Ive added two forms and it works proberly but suddenly after entering the username and the password, this error occurs "Vshost-clr2.exe has stop working"
and gives me two options whether to debug or to close program. Any help??!!!!
<pre>Imports System.Data.OleDb
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Define a connection to the databse with connection string
Dim connection As New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:UsersUserDesktopData.accdb")
Define sql command to retieve user name and password from database
Dim command As New OleDbCommand("select ID from database where username = @Username AND password = @Password", connection)
Dim usernameParam As New OleDbParameter("@Username", TextBox1.Text)
Dim passwordParam As New OleDbParameter("@Password", TextBox2.Text)
command.Parameters.Add(usernameParam)
command.Parameters.Add(passwordParam)
open connection
command.Connection.Open()
Dim userid As Integer = command.ExecuteScalar()
check if the query yeilds any result if not then there is no such user
If userid = 1 Then
if the query yeild no result then show a the no user label
Label3.Visible = True
Else
if there is a result then open form2 and send to it the userid
Dim form As New Form2
Form2.Show()
End If
close connection
command.Connection.Close()
End Sub
End Class[/code]
View the full article
i, I need to define sql command to retieve user name, password and balance from database.. Ive added two forms and it works proberly but suddenly after entering the username and the password, this error occurs "Vshost-clr2.exe has stop working"
and gives me two options whether to debug or to close program. Any help??!!!!
<pre>Imports System.Data.OleDb
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Define a connection to the databse with connection string
Dim connection As New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:UsersUserDesktopData.accdb")
Define sql command to retieve user name and password from database
Dim command As New OleDbCommand("select ID from database where username = @Username AND password = @Password", connection)
Dim usernameParam As New OleDbParameter("@Username", TextBox1.Text)
Dim passwordParam As New OleDbParameter("@Password", TextBox2.Text)
command.Parameters.Add(usernameParam)
command.Parameters.Add(passwordParam)
open connection
command.Connection.Open()
Dim userid As Integer = command.ExecuteScalar()
check if the query yeilds any result if not then there is no such user
If userid = 1 Then
if the query yeild no result then show a the no user label
Label3.Visible = True
Else
if there is a result then open form2 and send to it the userid
Dim form As New Form2
Form2.Show()
End If
close connection
command.Connection.Close()
End Sub
End Class[/code]
View the full article