View Single Post
  #1 (permalink)  
Old April 29th, 2008, 12:27 AM
greenbriar greenbriar is offline
Authorized User
Points: 68, Level: 1
Points: 68, Level: 1 Points: 68, Level: 1 Points: 68, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jul 2007
Location: Hansville, WA, USA.
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
Default hand code for datasets

Thyron:

I'm working with an ACCESS database I originally built with Access 97 and programmed with Visual Basic 4 designed to keep track of the amateur radio contacts I made over the last nineteen years. The database contains nearly 3200 entries. Last year I changed the format to ACCESS 2007 and now want to code it with VB 2005. I'm having trouble devleoping datasets and need help. I prefer to hand code the routines and have used Chapters 5 and 6 of "Beginning Visual Basic 2005 Databases" to develop the sub routine. The routine I use is:
 Private Sub frmContactsShow_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        'Establish a connection string
        Dim strConnectionString As String = _
        "Provider =Microsoft.Jet.OLEDB.4.0;" & _
        "Data Source=..:\ktplog.mdb;"
        Dim objConnection As New OleDbConnection(strConnectionString)
        ' Get the Query statement
        storedSQL = lblHidden.Text
        'Declare and initialize a new instance of the OleDbCommand class
        Dim objCommand As New OleDbCommand(storedSQL, objConnection)
        'Declare an OleDbDataAdapter obDject
        Dim objDataAdapter As New OleDbDataAdapter(objCommand)
        'Declare a Datatable object
        Dim objDataTable As New DataTable

        'Set the SelectCommand for the OleDbDataAdapter
        objDataAdapter.SelectCommand = objCommand

        'Populate the DataTable
        objDataAdapter.Fill(objDataTable)

        'Bind the DataTable to the DataGridView
        grdSelectedContacts.DataSource = objDataTable

        'Set the SelectionMode property
        grdSelectedContacts.SelectionMode = DataGridViewSelectionMode.FullRowSelect

        'Catch OleDbException As OleDbException
        'MessageBox.Show(OleDbException.Message, "N7KTP Contact Log Error")


The objCommand "StoredSQL" is a query passed from the previous screen using the lblHidden.Text property to perform the pass.
The query reads 'StoredSQL = "SELECT * FROM ContLog WHERE ContLog.Station LIKE '%" & Me.txtCallSignIn.Text & "%';"

My problem is that I get an OleDbException "Not a Valid File name"
when the progam reaches the line "objDataAdapter.Fill(objDataTable)" is executed. can you review my programming and tell me what I need to do to correct the problem?

Your book has helped me to grasp the new techniques of visual basic but I wish you wrote more examples of hand coating to help me do more hand coating which I feel more comfortable with.

Tnx...

Greenbriar
Reply With Quote