VBnikosnyc
New member
- Joined
- May 2, 2006
- Messages
- 4
- Programming Experience
- 1-3
Hi everyone,
i am making an application in vb.net with forms that connects to an access db. The forms have menus and in the beginning the app requires the user to login. The first form has 2 textfields and a "connect" button. When i press the connect button i want to query my access database and check a table if the user is active (if a column has a specific value ex. Y/N) and if the username and password given match those in the database.
My approach was to use the OleDbdatareader to access the data on my access db. My problem is when i run a simple query i can see the data but when i use the where clause in my sql statements i get an error at the
Reader = Cmd.ExecuteReader() line of my code.
what can i do so i can use where clauses in my sql statements?
is there another/better way to do it? Any comments will be helpful
thanks
here is my code
Dim Cmd As OleDb.OleDbCommand
Dim Con As OleDb.OleDbConnection
Dim Sql As String = Nothing
Dim Reader As OleDb.OleDbDataReader
Dim ComboRow As Integer = -1
Dim Columns As Integer = 0
Dim Category As String = Nothing
'CmbBoxMan.Items.Clear()
Dim s1, s2 As String
s1 = TextBox1.Text
s2 = TextBox2.Text
Con = New OleDb.OleDbConnection("Provider=Microsoft.Jet.OleDb.4.0;data source=c:\temp\college1.mdb")
Sql = "SELECT [FA_NAME] FROM [FACULTY]" ' WHERE [FA_ACCOUNT] = """ + s1 + """ And [FA_PIN] = " + s2 + ""
Cmd = New OleDb.OleDbCommand(Sql, Con)
Con.Open()
Reader = Cmd.ExecuteReader()
While Reader.Read()
For Columns = 0 To Reader.FieldCount - 1
Category = Reader.Item(Columns) 'READ COLUMN FROM DATABASE
Next
Label7.Text += Category
'CmbBoxMan.Items.Add(Category)
ComboRow += 1
End While
Con.Close()
i am making an application in vb.net with forms that connects to an access db. The forms have menus and in the beginning the app requires the user to login. The first form has 2 textfields and a "connect" button. When i press the connect button i want to query my access database and check a table if the user is active (if a column has a specific value ex. Y/N) and if the username and password given match those in the database.
My approach was to use the OleDbdatareader to access the data on my access db. My problem is when i run a simple query i can see the data but when i use the where clause in my sql statements i get an error at the
Reader = Cmd.ExecuteReader() line of my code.
what can i do so i can use where clauses in my sql statements?
is there another/better way to do it? Any comments will be helpful
thanks
here is my code
Dim Cmd As OleDb.OleDbCommand
Dim Con As OleDb.OleDbConnection
Dim Sql As String = Nothing
Dim Reader As OleDb.OleDbDataReader
Dim ComboRow As Integer = -1
Dim Columns As Integer = 0
Dim Category As String = Nothing
'CmbBoxMan.Items.Clear()
Dim s1, s2 As String
s1 = TextBox1.Text
s2 = TextBox2.Text
Con = New OleDb.OleDbConnection("Provider=Microsoft.Jet.OleDb.4.0;data source=c:\temp\college1.mdb")
Sql = "SELECT [FA_NAME] FROM [FACULTY]" ' WHERE [FA_ACCOUNT] = """ + s1 + """ And [FA_PIN] = " + s2 + ""
Cmd = New OleDb.OleDbCommand(Sql, Con)
Con.Open()
Reader = Cmd.ExecuteReader()
While Reader.Read()
For Columns = 0 To Reader.FieldCount - 1
Category = Reader.Item(Columns) 'READ COLUMN FROM DATABASE
Next
Label7.Text += Category
'CmbBoxMan.Items.Add(Category)
ComboRow += 1
End While
Con.Close()