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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. Visual Basic
  4. insert error

insert error

Scheduled Pinned Locked Moved Visual Basic
databasedebugginghelp
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.
  • K Offline
    K Offline
    kyosugi
    wrote on last edited by
    #1

    i trying to add info from user input n submit into the database i use the insert into -------------- Private Sub AddSubmitB_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AddSubmitB.Click Dim strcon As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Documents and Settings\Jasmine\My Documents\member\db1.mdb" Dim cmd As New OleDb.OleDbCommand Dim con As OleDb.OleDbConnection Dim dr As OleDb.OleDbDataReader Dim strsql As String con = New OleDb.OleDbConnection(strcon) con.Open() strsql = "Insert into member(BorrowerId, Fname, Lname, Gender, Address1, Address2, Address3) values('" & BorrowerIdTB.Text & "',' " & FnameTB.Text & "',' " & LnameTB.Text & "','" & GenderCLB.Text & "',' " & Add1TB.Text & "','" & Add2TB.Text & "',' " & Add3TB.Text & "')" cmd.Connection = con cmd.CommandText = strsql cmd.ExecuteNonQuery() con.Close() MsgBox("Record Added") Me.Close() End Sub -------------- when i run it the debugger stopped at cmd.ExecuteNonQuery() i seriously duno wat the error is about

    D 1 Reply Last reply
    0
    • K kyosugi

      i trying to add info from user input n submit into the database i use the insert into -------------- Private Sub AddSubmitB_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AddSubmitB.Click Dim strcon As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Documents and Settings\Jasmine\My Documents\member\db1.mdb" Dim cmd As New OleDb.OleDbCommand Dim con As OleDb.OleDbConnection Dim dr As OleDb.OleDbDataReader Dim strsql As String con = New OleDb.OleDbConnection(strcon) con.Open() strsql = "Insert into member(BorrowerId, Fname, Lname, Gender, Address1, Address2, Address3) values('" & BorrowerIdTB.Text & "',' " & FnameTB.Text & "',' " & LnameTB.Text & "','" & GenderCLB.Text & "',' " & Add1TB.Text & "','" & Add2TB.Text & "',' " & Add3TB.Text & "')" cmd.Connection = con cmd.CommandText = strsql cmd.ExecuteNonQuery() con.Close() MsgBox("Record Added") Me.Close() End Sub -------------- when i run it the debugger stopped at cmd.ExecuteNonQuery() i seriously duno wat the error is about

      D Offline
      D Offline
      Dave Kreskowiak
      wrote on last edited by
      #2

      It would help greatly if we knew what the error was! But, as a suggestion to clean up your code and make it easier to maintain, you might want to look into using parameterize queries instead of this string concantenation mess you've created. This is most likely where your problem is origination from. You can read more about parameterized queries and why they're a much better way to go in Colin Mackay's excellent article here[^].

      Dave Kreskowiak Microsoft MVP - Visual Basic

      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