Results 1 to 4 of 4

Thread: insert into access

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jan 2002
    Location
    Enterprise
    Posts
    101

    insert into access

    i have an app which maintains an access DB and i have a problem with inserting data into it
    i am using oledb.command and executing it as a nonquery command
    when i use the sql string which is built in the app directly in access the insert doesn't make any problems
    but when i try to run it in VB it always returns this error (attachment)
    can anyone help?
    thanks
    Attached Files Attached Files

  2. #2
    Thelonius
    Guest
    Can you post your code for the Insert? Make sure you have an open connection.

  3. #3
    Lively Member
    Join Date
    Feb 2001
    Location
    KL Malaysia
    Posts
    64
    object reference not set to an instance of an object... an error which got my jaw dropped for a while. it's just hte keyword new -- make sure you have all objects declared as new, like Dim objCmd as New OleDbCommand(strSQL, objConn) etc. without new would give you an error.

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Jan 2002
    Location
    Enterprise
    Posts
    101

    code

    Private Sub BtnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click
    Dim conAdd As OleDbConnection = New OleDbConnection(conExp.ConnectionString)
    Dim comAdd As OleDbCommand
    Dim comStr As String, den As String
    Dim comInt As Integer
    den = CStr(calAdd.SelectionStart)
    conAdd.Open()
    comStr = "insert into exp values(" + intID() + "," + intKat() + "," + CStr(txtSum.Text) + ",'" + CStr(den) + "','" + CStr(txtMemo.Text) + "')"
    comAdd.CommandText = comStr
    comInt = comAdd.ExecuteNonQuery()
    End Sub

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