Problem saving data to MS Access

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Goitse28
    New Member
    • Sep 2013
    • 4

    Problem saving data to MS Access

    Here is my code for a “Save” button on my VB Form:
    Code:
            Dim conStr As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|\TafitaDB.mdb;Persist Security Info=True"
            Dim objCon As New OleDbConnection(conStr)
            Dim sqlInsert As String = "insert into service values(@service_id,@service_type,@price)"
            Dim cmd As New OleDbCommand(sqlInsert, objCon)
    
            Try
                objCon.Open()
                cmd.Parameters.AddWithValue("@service_id", OleDbType.Integer).Value = txtServiceID.Text
                cmd.Parameters.AddWithValue("@service_type", OleDbType.WChar).Value = txtServType.Text
                cmd.Parameters.AddWithValue("@price", OleDbType.Currency).Value = txtPrice.Text
                cmd.ExecuteNonQuery()
                MsgBox("Data save successful", MsgBoxStyle.OkOnly, "Tafita Electronic System")
            Catch ex As Exception
                MsgBox(ex.Message, MsgBoxStyle.OkOnly, "Tafita Electronic System")
            Finally
                objCon.Close()
                objCon.Dispose()
            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.
    Last edited by Rabbit; Sep 3 '13, 08:58 PM. Reason: Please use code tags when posting code.
  • zmbd
    Recognized Expert Moderator Expert
    • Mar 2012
    • 5501

    #2
    VB or VBA - slight difference in flavors

    Comment

    • Goitse28
      New Member
      • Sep 2013
      • 4

      #3
      I'm using vb.net to create my programs.

      Comment

      • zmbd
        Recognized Expert Moderator Expert
        • Mar 2012
        • 5501

        #4
        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.
        Last edited by zmbd; Sep 4 '13, 05:57 AM.

        Comment

        • Goitse28
          New Member
          • Sep 2013
          • 4

          #5
          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.

          Comment

          • zmbd
            Recognized Expert Moderator Expert
            • Mar 2012
            • 5501

            #6
            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.
            Last edited by zmbd; Sep 7 '13, 01:31 AM.

            Comment

            • Goitse28
              New Member
              • Sep 2013
              • 4

              #7
              Ok thanx again. I hope a permanent solution will be available.

              Comment

              Working...