|
-
October 10th, 2010, 11:54 AM
#1
Sql Database Connection
whats wrong with my codes, i cant connect to my database...pls help!
ERROR CONNECTING TO DATABASE
Imports System.Data.SqlClient
Imports System.Data
Public Class LoginForm1
' TODO: Insert code to perform custom authentication using the provided username and password
' (See http://go.microsoft.com/fwlink/?LinkId=35339).
' The custom principal can then be attached to the current thread's principal as follows:
' My.User.CurrentPrincipal = CustomPrincipal
' where CustomPrincipal is the IPrincipal implementation used to perform authentication.
' Subsequently, My.User will return identity information encapsulated in the CustomPrincipal object
' such as the username, display name, etc.
Private Sub OK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdOK.Click
Dim conn As SqlConnection
conn = New SqlConnection()
conn.ConnectionString = "Data Source=JING2; Initial Catalog=AFJIS"
Try
conn.Open()
Catch myerror As SqlException
MsgBox("Error Connecting to Database")
End Try
Dim MyAdapter As New SqlDataAdapter
Dim Sqlquery = "Select * From syscontrol Where username = '" + txtuser.Text + "' And
password = '" + txtpass.Text + "'"
Dim MyCommand As New MySqlCommand()
MyCommand.Connection.conn()
MyCommand.Commandtext = Sqlquery
Dim MyData As SqlDataReader
MyData = MyCommand.ExecuteReader()
If MyData.HasRows = 0 Then
MsgBox("Invalid Login")
Else
MsgBox("Login Accepted")
Me.Hide()
End If
Me.Close()
End Sub
Private Sub Cancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Cancel.Click
Me.Close()
End Sub
End Class
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|