By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
444,041 Members | 1,018 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 444,041 IT Pros & Developers. It's quick & easy.

Problem saving data to MS Access

P: 4
Here is my code for a “Save” button on my VB Form:
Expand|Select|Wrap|Line Numbers
  1.         Dim conStr As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|\TafitaDB.mdb;Persist Security Info=True"
  2.         Dim objCon As New OleDbConnection(conStr)
  3.         Dim sqlInsert As String = "insert into service values(@service_id,@service_type,@price)"
  4.         Dim cmd As New OleDbCommand(sqlInsert, objCon)
  5.  
  6.         Try
  7.             objCon.Open()
  8.             cmd.Parameters.AddWithValue("@service_id", OleDbType.Integer).Value = txtServiceID.Text
  9.             cmd.Parameters.AddWithValue("@service_type", OleDbType.WChar).Value = txtServType.Text
  10.             cmd.Parameters.AddWithValue("@price", OleDbType.Currency).Value = txtPrice.Text
  11.             cmd.ExecuteNonQuery()
  12.             MsgBox("Data save successful", MsgBoxStyle.OkOnly, "Tafita Electronic System")
  13.         Catch ex As Exception
  14.             MsgBox(ex.Message, MsgBoxStyle.OkOnly, "Tafita Electronic System")
  15.         Finally
  16.             objCon.Close()
  17.             objCon.Dispose()
  18.         End Try
My problem is that when I click the “Save” button on my Form nothing is saved on my MS Access DB. Can anyone help me please? Thanks in advance.
Sep 3 '13 #1
Share this Question
Share on Google+
6 Replies


zmbd
Expert Mod 5K+
P: 5,397
VB or VBA - slight difference in flavors
Sep 3 '13 #2

P: 4
I'm using vb.net to create my programs.
Sep 4 '13 #3

zmbd
Expert Mod 5K+
P: 5,397
More than likely we'll need to move this thread to either VB or .Net forum...

even before we get this moved, now that we know what language you are using, someone will come along to help so hang in there!

In the meantime, please provide a LOT more detail about which version of the .Net you are using, what version of the Access datbase you are trying to connect to, what operating system you working under.
ANY ERRORS! Complete with Title, Number, and Description as given in the dialog...

IN VBA, I'd have you do a compile, I'm sure there's the equivalent in your editor, I'd suggest that and fix any errors that popup

And just because I can... I'm going to take a poke in the dark and suggest that you verify your connection string in line 1, and I absolutly detest the way line 2 is used to create your object... I see this in VBA and often there's an issue... better (IMHO) to cast the object variable as object and the "SET" the object in a seperate line. I know that MS shows the method you've used as the "new" and "exciting" method; however, it makes troubleshooting a real pain.
Sep 4 '13 #4

P: 4
thnx 4 help. I managed to find a way to save data from a form to access.mdb. I moved the db to a debug folder. I'm not sure whether its the right thing to do but it works.
Sep 6 '13 #5

zmbd
Expert Mod 5K+
P: 5,397
Sorry about the delay....
I sent this over to be discussed as to which forum would be most helpful for your question.

As for your current solution, I think that is only a temporary means to an end.

Hopefully someone with more knowledge will be able to point you towards a more permanent solution.
Sep 7 '13 #6

P: 4
Ok thanx again. I hope a permanent solution will be available.
Sep 8 '13 #7

Post your reply

Sign in to post your reply or Sign up for a free account.