Wrox Programmer Forums
|
VB Databases Basics Beginning-level VB coding questions specific to using VB with databases. Issues not specific to database use will be redirected to other forums.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the VB Databases Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old May 2nd, 2006, 06:13 AM
Registered User
 
Join Date: May 2006
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default DALBase? and Oledbdatareader

Hi everyone

i was going through the book vb.net & databases and i was stuck at chapter 6.
What is the DALBase? i tried to use it when i was writing code but i get errors.

Also i tried to use the oledbdatareader with a sql statement that includes the where clause. When i include the where its not working and when i take it off its working fine any ideas?


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.OleD b.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()

 
Old May 2nd, 2006, 08:06 AM
Friend of Wrox
 
Join Date: May 2006
Posts: 643
Thanks: 0
Thanked 0 Times in 0 Posts
Default

When you build the string for the select statement you need to use single quotes when you include the s1 and s2 variables:

Sql = "SELECT [FA_NAME] FROM [FACULTY]" ' WHERE [FA_ACCOUNT] = "'" + s1 + "'" And [FA_PIN] = "'" + s2 + "'"


Woody Z http://www.learntoprogramnow.com
 
Old May 2nd, 2006, 09:08 AM
Registered User
 
Join Date: May 2006
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Yes ofcourse, my sql syntax is a little rusty. It worked out fine now! Thanks woodyz!!






Similar Threads
Thread Thread Starter Forum Replies Last Post
What is OleDBDataReader.GetValue() means? Dragonist ADO.NET 2 July 5th, 2004 07:24 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.