Results 1 to 5 of 5

Thread: VB 2010 Express problem with database connectivity

  1. #1

    Thread Starter
    New Member
    Join Date
    Feb 2012
    Posts
    3

    VB 2010 Express problem with database connectivity

    First of all i don't have
    any syntax error before RUN my form after that... When I try to UPDATE the database (access.databese)
    and with adding NEW customer but I get "oleDbException was unhandled" and the database isn't UPDATE,
    I have also try a code that I design (see below the code) since the save bottom at the toolbar it was empty (as default ) but isn't helps me, I get other similar problem Insert Into has syntax error...... I don't know what to do...

    Now I really believe that the problem is that the compiler when open the database (access) it's initialize the first TABLE of NorthWind(MAIN TABLE) so when I call the compiler to open the database open the first table and when I try to UPDATE the table of Customers CANNOT find any Table = Customers and prints out the error... (since the compiler open the NorthWind main table and I am trying to UPDATE the Customer TABLE) So i need
    to send the compiler into the correct Position at the database but I don't know how to do.....

    I am searching 3 days now and I didn't find any solution in google so PLEASE if you have any ideas let me know as soon as possible because it's imagery I have to presetting the project at the middle of the week below it's the CODE that I have done maybe thats HELPS you....

    Thank you in advance!!!

    VB Code:
    1. Imports Access = Microsoft.Office.Interop.Access
    2. Imports System.Data
    3. Imports System.Data.OleDb
    4. Public Class Form1
    5.     Dim provider As String
    6.     Dim dataFile As String
    7.     Dim connString As String
    8.     Dim myConnection As OleDbConnection = New OleDbConnection
    9.  
    10.     Private Sub SaveButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) HandlesSaveButton.Click
    11.         provider = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source ="
    12.         dataFile = "C:\Users\USER_NAME\Documents\NorthWind_2007.accdb"
    13.         connString = provider & dataFile
    14.         myConnection.ConnectionString = connString
    15.  
    16.         myConnection.Open()
    17.         Dim str As String
    18.         str = "insert into Items ([ID], [First Name], [Last Name], [Street], [Phone]) values (?, ?, ?, ?, ?)"
    19.         Dim cmd As OleDbCommand = New OleDbCommand(str, myConnection)
    20.  
    21.         Dim cmd As OleDbCommand = New OleDbCommand(str, myConnection)
    22.         cmd.Parameters.Add(New OleDbParameter("ID", CType(TextBox1.Text, String)))
    23.         cmd.Parameters.Add(New OleDbParameter("Fist Name", CType(TextBox2.Text, String)))
    24.         cmd.Parameters.Add(New OleDbParameter("Last Name", CType(TextBox3.Text, String)))
    25.         cmd.Parameters.Add(New OleDbParameter("Street", CType(TextBox4.Text, String)))
    26.         cmd.Parameters.Add(New OleDbParameter("Phone", CType(TextBox5.Text, String)))
    27.         Try
    28.             cmd.ExecuteNonQuery()
    29.         Catch ex As Exception
    30.             MsgBox(ex.Message)
    31.         End Try
    32.         TextBox1.Clear()
    33.         TextBox2.Clear()
    34.         TextBox3.Clear()
    35.         TextBox4.Clear()
    36.         TextBox5.Clear()
    37.  
    38.     End Sub
    39. End Class

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: VB 2010 Express problem with database connectivity

    The IDE gives you far more information than just the fact that an exception was unhandled. It gives you access to the exception itself, which contains lots of information about what went wrong and where. You are supposed to look at that information and use it to diagnose the problem. If you are unable to do so and you would like us to diagnose the issue for you then you should provide us with that information.

    That said, it seems odd that an exception is going unhandled when you are using a Try...Ctach block for the ExecuteNonQuery call.

    Finally, where are you closing the connection you opened?
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    New Member
    Join Date
    Feb 2012
    Posts
    3

    Re: VB 2010 Express problem with database connectivity

    :-/ ooooo so it's that I open something, what ever it's I edit and I didn't close it... :-/ that really dumb :P I will try that with

    vb Code:
    1. myConnection.Close()

    what about the ExecuteNonQuery?? maybe because of the connection it's corrupted?? As I mention at the beginning of my post I was pretty sure that my problem was with the directories.. .Since I was open the file my let think like the compiler if I manually open the database I get into the main page of the table I CAN'T edit the customer's table so why compiler can do that?? My thought was that the compiler was trying to insert details into a wrong direction that the reason that the program crash... seams to have some logic but A lot of logic has your thought....!!! I didn't close my connection that could be another mistake of me... Anyway I will try your advice and I would let you know... Thank you very much for your understanding and your help...!!!! cheeeeerssssss!!!!

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: VB 2010 Express problem with database connectivity

    It's an issue that you didn't close the connection but that is not related to the error you're asking about. Please provide the information I asked for in my previous post.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  5. #5

    Thread Starter
    New Member
    Join Date
    Feb 2012
    Posts
    3

    Re: VB 2010 Express problem with database connectivity

    Thanks jmcilhinney Unfortunately I don't have any windows machine right now to provide exactly the information of Try...Catch and give you more info about the error that I get, so I will post the whole error as the IDE output at the end of the day.....!!! Thank you again for your help...!!!!!!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width