Wrox Programmer Forums
|
Visual Basic 2010 General Discussion For any discussions about Visual Basic 2010 topics which aren't related to a specific Wrox book
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Visual Basic 2010 General Discussion 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 April 3rd, 2012, 05:19 PM
Registered User
 
Join Date: Nov 2011
Posts: 9
Thanks: 2
Thanked 0 Times in 0 Posts
Default OdbcConnection

In this block of code I am simply trying to open an access 2010 database (accdb) and fill a data table. However when code is run I get
error [IM002][Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified.

On a different form I use a DataGridView, DataSet, BindingSource and a
TableAdapter for the toolbox to open and view the same table, which functions fine.
The web is pointing me to the connection str, however I cannot find what is wrong. Any help is of course appreciated
Code:
Imports System.Data.Odbc

Public Class Form1

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

        Dim conn As OdbcConnection
        Dim cmd As OdbcCommand
        Dim da As OdbcDataAdapter
        Dim query As String
        Dim connString As String = ""
        connString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\Rick\Desktop\Aeroparts.accdb;Persist Security Info=False;"

        query = "SELECT[*] FROM [Statuscodes]"
        'Create the connection object
        conn = New OdbcConnection(connString)
        'Open connection
        cmd = New OdbcCommand(query, conn)
        da = New OdbcDataAdapter(cmd)
        Dim AeroPartsDataSet = New DataSet()
        Dim StationTimeTable As DataTable = AeroPartsDataSet.Tables.Add("StationTimeTable")

        Try
            conn.Open()
        Catch ex As Exception
            MsgBox(ex.Message, MsgBoxStyle.Critical)
        End Try
        Try
            'da.Fill(StationTimeTable)
            da.Dispose() 'close data adapter
            conn.Close() 'close connect to Spreadsheet
            conn.Dispose() 'do cleanup of connection enviroment
        Catch ex As Exception
            MsgBox(ex.Message, MsgBoxStyle.Critical)
        End Try

    End Sub


End Class
 
Old April 4th, 2012, 07:43 AM
Registered User
 
Join Date: Mar 2012
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

thanks for replying.

I have one more problem if u can help me..

Wants to add new row and delete row to data bounded grid.
data is bounded through tools from tool box, binding source ,data set.
Whatever changes made is upto data set only, not able to save it to database.

I searched and found that new row can be added to data source directly. but How?...









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