|
-
Feb 16th, 2012, 08:32 PM
#1
Thread Starter
New Member
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:
Imports Access = Microsoft.Office.Interop.Access
Imports System.Data
Imports System.Data.OleDb
Public Class Form1
Dim provider As String
Dim dataFile As String
Dim connString As String
Dim myConnection As OleDbConnection = New OleDbConnection
Private Sub SaveButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) HandlesSaveButton.Click
provider = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source ="
dataFile = "C:\Users\USER_NAME\Documents\NorthWind_2007.accdb"
connString = provider & dataFile
myConnection.ConnectionString = connString
myConnection.Open()
Dim str As String
str = "insert into Items ([ID], [First Name], [Last Name], [Street], [Phone]) values (?, ?, ?, ?, ?)"
Dim cmd As OleDbCommand = New OleDbCommand(str, myConnection)
Dim cmd As OleDbCommand = New OleDbCommand(str, myConnection)
cmd.Parameters.Add(New OleDbParameter("ID", CType(TextBox1.Text, String)))
cmd.Parameters.Add(New OleDbParameter("Fist Name", CType(TextBox2.Text, String)))
cmd.Parameters.Add(New OleDbParameter("Last Name", CType(TextBox3.Text, String)))
cmd.Parameters.Add(New OleDbParameter("Street", CType(TextBox4.Text, String)))
cmd.Parameters.Add(New OleDbParameter("Phone", CType(TextBox5.Text, String)))
Try
cmd.ExecuteNonQuery()
Catch ex As Exception
MsgBox(ex.Message)
End Try
TextBox1.Clear()
TextBox2.Clear()
TextBox3.Clear()
TextBox4.Clear()
TextBox5.Clear()
End Sub
End Class
-
Feb 17th, 2012, 07:51 PM
#2
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?
-
Feb 18th, 2012, 10:05 AM
#3
Thread Starter
New Member
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
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!!!!
-
Feb 18th, 2012, 10:12 AM
#4
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.
-
Feb 18th, 2012, 10:25 AM
#5
Thread Starter
New Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|