|
-
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
-
October 10th, 2010, 01:23 PM
#2
Re: Sql Database Connection
Doesn't look like a valid connection string.
Find what you need here:
-
October 12th, 2010, 09:07 AM
#3
Re: Sql Database Connection
Yeah... I can tell just by looking at that connection string, it's not valid for SQL Server. OR... conversely, the use of the SQLClient namespace isn't valid for the type of database being connected to.
-tg
-
October 12th, 2010, 05:11 PM
#4
Re: Sql Database Connection
In vb.net, I created upload button to upload csv file to MS Access in vb.net. Can you please help me with coding to upload csv file.
-
October 12th, 2010, 06:18 PM
#5
Re: Sql Database Connection
Your question has been answered. Please don't double-post.
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
|