h.rezaee
یک شنبه 11 دی 1390, 16:02 عصر
سلام بر دوستان عزیز. من یه پروژه دارم می نویسم منتها تو اتصال دادن به بانک اطلاعاتی دچار مشکل شدم. می خوام برای login شدن تا زمانی که user و pass درست نباشه وارد برنامه نشه. کدم رو میزارم ببینید تو کجا مشکل داره . ممنون میشم اگه کمکم کنید.
Imports System.Data.SqlClient
Imports System.Data
Public Class login
Dim sqlquery As String
Dim conn As New SqlConnection("Data Source=(local);Initial Catalog=Dabirkhane;Integrated Security=True")
Dim comm As New SqlCommand
Dim adapt As New SqlDataAdapter
Dim Database1DataSet As New DataSet
Private Sub ConnectToSQL()
Dim con As New SqlConnection
Dim cmd As New SqlCommand
Try
con.ConnectionString = "Data Source=atisource;Initial Catalog=BillingSys;Persist Security Info=True;User ID=dabirkhane;Password=ekbatan1390"
con.Open()
Catch ex As Exception
MessageBox.Show("Error while connecting to Server." & ex.Message)
con.Close() 'Whether there is error or not. Close the connection.
End Try
End Sub
Private Sub Cancel_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Cancel.Click
Me.Close()
End Sub
Private Sub OK_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OK.Click
conn.Open()
Dim sql As String
sql = "SELECT USERNAME,PASSWORD FROM USERS WHERE USERNAME= '" & usertxt.Text & " ' AND PASSWORD='" & passtxt.Text & "'"
adapt.SelectCommand = New SqlCommand(sql, conn)
Dim myReader As SqlDataReader = comm.ExecuteReader()
If myReader.Read() = False Then
MessageBox.Show("Error while inserting record o")
Else
If myReader.Read() = True Then
mainfrm.Show()
End If
End If
End Sub
End Class
ببینید موقع run کردن برنامه به خط زیر گیر میده:
Dim myReader As SqlDataReader = comm.ExecuteReader()
Imports System.Data.SqlClient
Imports System.Data
Public Class login
Dim sqlquery As String
Dim conn As New SqlConnection("Data Source=(local);Initial Catalog=Dabirkhane;Integrated Security=True")
Dim comm As New SqlCommand
Dim adapt As New SqlDataAdapter
Dim Database1DataSet As New DataSet
Private Sub ConnectToSQL()
Dim con As New SqlConnection
Dim cmd As New SqlCommand
Try
con.ConnectionString = "Data Source=atisource;Initial Catalog=BillingSys;Persist Security Info=True;User ID=dabirkhane;Password=ekbatan1390"
con.Open()
Catch ex As Exception
MessageBox.Show("Error while connecting to Server." & ex.Message)
con.Close() 'Whether there is error or not. Close the connection.
End Try
End Sub
Private Sub Cancel_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Cancel.Click
Me.Close()
End Sub
Private Sub OK_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OK.Click
conn.Open()
Dim sql As String
sql = "SELECT USERNAME,PASSWORD FROM USERS WHERE USERNAME= '" & usertxt.Text & " ' AND PASSWORD='" & passtxt.Text & "'"
adapt.SelectCommand = New SqlCommand(sql, conn)
Dim myReader As SqlDataReader = comm.ExecuteReader()
If myReader.Read() = False Then
MessageBox.Show("Error while inserting record o")
Else
If myReader.Read() = True Then
mainfrm.Show()
End If
End If
End Sub
End Class
ببینید موقع run کردن برنامه به خط زیر گیر میده:
Dim myReader As SqlDataReader = comm.ExecuteReader()