Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Visual Basic > VB 6 Visual Basic 6 > VB Databases Basics
|
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 30th, 2006, 10:16 AM
Registered User
 
Join Date: May 2006
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default An unhandled exception of type 'System.Data.OleDb.

Hello,

Can anyone help with my problem. I am trying to create a search facility that will search from car makes in a combo box using an Access database, however i have got stuck. I have populated te combo box but when i click search i receive the following error.

An unhandled exception of type 'System.Data.OleDb.OleDbException' occurred in system.data.dll

Can anyone tell me what i do to overcome this. The error is related to the BtnSearch code which i have made bold and italic. The error is created specfically on the OleDbDataAdapter1.Fill(DataSet1)line. Although i have used the same code in the form load section with no errors.

I understand very little of VB.NET as i have only just started using it.

Imports System
Imports System.Data
Imports System.Data.OleDb
Public Class Form1
    Inherits System.Windows.Forms.Form
    Dim Conn As New OleDb.OleDbConnection
    Dim Comm As New OleDb.OleDbCommand
    Dim Reader As OleDb.OleDbDataReader


    Private Sub DataGrid1_Navigate(ByVal sender As System.Object, ByVal ne As System.Windows.Forms.NavigateEventArgs) Handles DataGrid1.Navigate

    End Sub
    Private Sub getData()
        DataSet1.Clear()
        OleDbDataAdapter1.Fill(DataSet1)
        DataGrid1.SetDataBinding(DataSet1, "T_Vehicle")
    End Sub

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        getData()
        fillCombo()
    End Sub

    Private Sub OleDbConnection1_InfoMessage(ByVal sender As System.Object, ByVal e As System.Data.OleDb.OleDbInfoMessageEventArgs) Handles OleDbConnection1.InfoMessage

    End Sub

    Private Sub OleDbDataAdapter1_RowUpdated(ByVal sender As System.Object, ByVal e As System.Data.OleDb.OleDbRowUpdatedEventArgs) Handles OleDbDataAdapter1.RowUpdated

    End Sub
    Private Sub fillCombo()

        Try
            makeConn(Conn)

            Comm.CommandText = "SELECT Distinct Make FROM T_Vehicle; "
            Comm.Connection = Conn
            Reader = Comm.ExecuteReader(CommandBehavior.SequentialAcces s)


            Do While Reader.Read

                ComboMake.Items.Add(Reader.GetValue(0).ToString)

            Loop

        Catch grE As Exception
            MsgBox(grE.Message)
        Finally
            Reader.Close()
            Conn.Close()
        End Try

    End Sub

    Private Sub makeConn(ByVal newConn As OleDb.OleDbConnection)

        newConn.ConnectionString = _
            "Provider=Microsoft.Jet.OLEDB.4.0;" & _
            "Persist Security Info=False;" & _
            "User ID=Admin;" & _
            "Data Source=F:\VehFinda.mdb;"
        newConn.Open()
    End Sub
Private Sub BtnSearch_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnSearch.Click


        OleDbDataAdapter1.SelectCommand.CommandText = _
                 "SELECT Make FROM T_Vehicle " & _
                 "WHERE Make = " & (ComboMake.Text)


        DataSet1.Clear()
        OleDbDataAdapter1.Fill(DataSet1)
        DataGrid1.SetDataBinding(DataSet1, "T_Vehicle")

    End Sub


    Private Sub BtnBrowse_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnBrowse.Click
        OleDbDataAdapter1.SelectCommand.CommandText = _
        "Select * From T_Vehicle"

    End Sub

    Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboMake.SelectedIndexChanged

    End Sub

End Class

Thank you
Harvey

HAS
 
Old May 30th, 2006, 12:57 PM
Friend of Wrox
 
Join Date: Oct 2004
Posts: 224
Thanks: 0
Thanked 1 Time in 1 Post
Send a message via MSN to ashu_from_india Send a message via Yahoo to ashu_from_india
Default

hi Harvey

wht is the DataType of Make field

if its Numeric then use Val(Combo.text)
and if its Varchar then use "'" & Combo.text & "'"

i hope it will help

cheers :)

Ashu







Similar Threads
Thread Thread Starter Forum Replies Last Post
An unhandled exception of type 'System.Data.SqlCli BB VB.NET 2002/2003 Basics 5 February 21st, 2014 10:22 AM
unhandled exception dipakp ASP.NET 2.0 Professional 1 July 6th, 2007 02:16 PM
System.Data.OleDb.OleDbException: No value given f tjgrindsted ASP.NET 2.0 Basics 0 January 24th, 2007 07:25 AM
System.Data.OleDb.OleDbException: Expected query n Thac Classic ASP Databases 0 July 3rd, 2005 01:48 PM
unhandled exception of type 'System.Net.WebExcepti booksnore2 C# 0 June 26th, 2004 07:26 AM





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