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. Problem in OleDbDataAdapter.Update [modified]

Problem in OleDbDataAdapter.Update [modified]

Scheduled Pinned Locked Moved Visual Basic
helpcssdatabasequestionannouncement
1 Posts 1 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.
  • A Offline
    A Offline
    azusakt
    wrote on last edited by
    #1

    Hi, I have to do updates to my mdb access database, which has 2 column, user_name and user_pwd. I have followed the suggestion from MSDN, but I don't know it still got error when excuting update().It says "Update command" or "Insert Command" to have connection object... Can someone give me some hints or point out to me that What I missed? Here is my code: Dim connStr As String = ("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Application.StartupPath & "\me.mdb") Dim sqlStr As String = "SELECT * FROM wpLogin" Dim dt As New DataTable() Dim dataAdapter As OleDbDataAdapter Dim ODBconn As OleDbConnection Public Function CreateDataAdapter(ByVal selectCommand As String, ByVal connection As OleDbConnection) As OleDbDataAdapter Dim adapter As OleDbDataAdapter = New OleDbDataAdapter(selectCommand, connection) adapter.MissingSchemaAction = MissingSchemaAction.AddWithKey ' Create the commands. adapter.InsertCommand = New OleDbCommand( _ "INSERT INTO wpLogin (user_name, user_pwd) " & _ "VALUES (?, ?)") adapter.UpdateCommand = New OleDbCommand( _ "UPDATE wpLogin SET user_name = ?, user_pwd = ? " & _ "WHERE user_name = ?") adapter.DeleteCommand = New OleDbCommand("DELETE FROM wpLogin WHERE user_name = ?") ' Create the parameters. adapter.InsertCommand.Parameters.Add( _ "@user_name", OleDbType.Char, 50, "user_name") adapter.InsertCommand.Parameters.Add( _ "@user_pwd", OleDbType.Char, 50, "user_pwd") adapter.UpdateCommand.Parameters.Add( _ "@user_name", OleDbType.Char, 50, "user_name") adapter.UpdateCommand.Parameters.Add( _ "@user_pwd", OleDbType.Char, 50, "user_pwd") adapter.DeleteCommand.Parameters.Add( _ "@user_name", OleDbType.Char, 50, "user_name").SourceVersion = _ DataRowVersion.Original Return adapter End Function Private Sub btnEdit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnEdit.Click 'Displays the table's data in the data grid 'Clear the current contents of the table dt.Clear() 'Fill the data table with data from the database 'Dim dataAdapter As New OleDb.OleDbDataAdapter(sqlStr, connStr) ODBconn = New OleDbConnection(connStr) dataAdapter = CreateDataAdapter(sqlStr, ODBconn

    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