Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. adding to access database

adding to access database

Scheduled Pinned Locked Moved Visual Basic
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    peteyshrew
    wrote on last edited by
    #1

    right now i'm trying to add data to a database. i think i'm almost their but get this error message "Property access must assign to the property or use its value" this is what code i got Imports System.Data.OleDb Public Class Cust Inherits System.Windows.Forms.Form Dim cn As OleDbConnection Dim cmd As OleDbCommand Dim dr As OleDbDataReader Dim icount As Integer Dim str As String Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click Try cn = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\PCBank.mdb;") cn.Open() str = "insert into customer values(" & CInt(tbID.Text) & ",'" & tbSur.Text & "','" & tbFor.Text & "')" 'string stores the command and CInt is used to convert number to string cmd = New OleDbCommand(str, cn) icount = cmd.ExecuteNonQuery MessageBox.Show(icount) 'displays number of records inserted Catch End Try cn.Close() End Sub End Class can anybody enliten me?

    D 1 Reply Last reply
    0
    • P peteyshrew

      right now i'm trying to add data to a database. i think i'm almost their but get this error message "Property access must assign to the property or use its value" this is what code i got Imports System.Data.OleDb Public Class Cust Inherits System.Windows.Forms.Form Dim cn As OleDbConnection Dim cmd As OleDbCommand Dim dr As OleDbDataReader Dim icount As Integer Dim str As String Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click Try cn = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\PCBank.mdb;") cn.Open() str = "insert into customer values(" & CInt(tbID.Text) & ",'" & tbSur.Text & "','" & tbFor.Text & "')" 'string stores the command and CInt is used to convert number to string cmd = New OleDbCommand(str, cn) icount = cmd.ExecuteNonQuery MessageBox.Show(icount) 'displays number of records inserted Catch End Try cn.Close() End Sub End Class can anybody enliten me?

      D Offline
      D Offline
      DaveRRR
      wrote on last edited by
      #2

      I might have the answer you seek, but I haven't looked in any depth at this problem.

      It may be something to do with the insert statement and/or the customer table. Does the table only have 3 columns: an id, a surname and a forename? Is the id column auto-generated (or whatever the term is in MS Access)? Try naming the columns in your insert statement. I don't know what columns your customer table has but it might be something like this:

      insert into customer (id, surname, forename) values (99, 'Rogers', 'Dave')

      Dave

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups