Results 1 to 6 of 6
  1. #1
    Join Date
    Mar 2008
    Location
    Netherlands
    Posts
    18

    Unhappy Unanswered: Problem updating records Pervasive db.

    Hello,
    I am a beginner in vb.net. I want to read and write records from a Pervasive db.
    Getting data works fine, but when i want to update a record i get an error which i do not understand.
    "Object not set to an instance of aan object" System.NullReferenceException

    The table doesn't have primary key, only indexes. That's what the data link configurator tells me.
    Maybe somebody knows more.
    Pervasive v8.6, vb.net 2002.


    Imports Pervasive.Data
    Public Class frmUpdatePP
    Inherits System.Windows.Forms.Form

    #Region " Windows Form Designer generated code "

    Public Sub New()
    MyBase.New()

    'This call is required by the Windows Form Designer.
    InitializeComponent()

    'Add any initialization after the InitializeComponent() call

    End Sub

    'Form overrides dispose to clean up the component list.
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
    If disposing Then
    If Not (components Is Nothing) Then
    components.Dispose()
    End If
    End If
    MyBase.Dispose(disposing)
    End Sub

    'Required by the Windows Form Designer
    Private components As System.ComponentModel.IContainer

    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer.
    'Do not modify it using the code editor.
    Friend WithEvents btnMerkcode As System.Windows.Forms.Button
    Friend WithEvents txtArtnr As System.Windows.Forms.TextBox
    Friend WithEvents txtZoeknaam As System.Windows.Forms.TextBox
    Friend WithEvents btnUpdate As System.Windows.Forms.Button
    Friend WithEvents DbRidderart As System.Data.OleDb.OleDbDataAdapter
    Friend WithEvents OleDbSelectCommand1 As System.Data.OleDb.OleDbCommand
    Friend WithEvents OleDbInsertCommand1 As System.Data.OleDb.OleDbCommand
    Friend WithEvents ConnRidderart As System.Data.OleDb.OleDbConnection
    Friend WithEvents OleDbUpdateCommand1 As System.Data.OleDb.OleDbCommand
    Friend WithEvents DsRidderart As Merkcode.DsRidderart
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
    Me.txtArtnr = New System.Windows.Forms.TextBox()
    Me.txtZoeknaam = New System.Windows.Forms.TextBox()
    Me.btnMerkcode = New System.Windows.Forms.Button()
    Me.btnUpdate = New System.Windows.Forms.Button()
    Me.DbRidderart = New System.Data.OleDb.OleDbDataAdapter()
    Me.OleDbInsertCommand1 = New System.Data.OleDb.OleDbCommand()
    Me.ConnRidderart = New System.Data.OleDb.OleDbConnection()
    Me.OleDbSelectCommand1 = New System.Data.OleDb.OleDbCommand()
    Me.OleDbUpdateCommand1 = New System.Data.OleDb.OleDbCommand()
    Me.DsRidderart = New Merkcode.DsRidderart()
    CType(Me.DsRidderart, System.ComponentModel.ISupportInitialize).BeginIni t()
    Me.SuspendLayout()
    '
    'txtArtnr
    '
    Me.txtArtnr.Location = New System.Drawing.Point(48, 80)
    Me.txtArtnr.Name = "txtArtnr"
    Me.txtArtnr.Size = New System.Drawing.Size(128, 20)
    Me.txtArtnr.TabIndex = 0
    Me.txtArtnr.Text = ""
    '
    'txtZoeknaam
    '
    Me.txtZoeknaam.Location = New System.Drawing.Point(48, 112)
    Me.txtZoeknaam.Name = "txtZoeknaam"
    Me.txtZoeknaam.Size = New System.Drawing.Size(128, 20)
    Me.txtZoeknaam.TabIndex = 1
    Me.txtZoeknaam.Text = ""
    '
    'btnMerkcode
    '
    Me.btnMerkcode.Location = New System.Drawing.Point(48, 32)
    Me.btnMerkcode.Name = "btnMerkcode"
    Me.btnMerkcode.TabIndex = 1
    Me.btnMerkcode.Text = "Merkcode"
    '
    'btnUpdate
    '
    Me.btnUpdate.Location = New System.Drawing.Point(144, 32)
    Me.btnUpdate.Name = "btnUpdate"
    Me.btnUpdate.TabIndex = 2
    Me.btnUpdate.Text = "Update"
    '
    'DbRidderart
    '
    Me.DbRidderart.InsertCommand = Me.OleDbInsertCommand1
    Me.DbRidderart.SelectCommand = Me.OleDbSelectCommand1
    Me.DbRidderart.TableMappings.AddRange(New System.Data.Common.DataTableMapping() {New System.Data.Common.DataTableMapping("Table", "ARTIKEL", New System.Data.Common.DataColumnMapping() {New System.Data.Common.DataColumnMapping("ARTIKELNUMME R", "ARTIKELNUMMER"), New System.Data.Common.DataColumnMapping("ZOEKNAAM", "ZOEKNAAM")})})
    Me.DbRidderart.UpdateCommand = Me.OleDbUpdateCommand1
    '
    'OleDbInsertCommand1
    '
    Me.OleDbInsertCommand1.CommandText = "INSERT INTO ARTIKEL(ARTIKELNUMMER, ZOEKNAAM) VALUES (?, ?)"
    Me.OleDbInsertCommand1.Connection = Me.ConnRidderart
    Me.OleDbInsertCommand1.Parameters.Add(New System.Data.OleDb.OleDbParameter("ARTIKELNUMMER", System.Data.OleDb.OleDbType.VarChar, 17, "ARTIKELNUMMER"))
    Me.OleDbInsertCommand1.Parameters.Add(New System.Data.OleDb.OleDbParameter("ZOEKNAAM", System.Data.OleDb.OleDbType.VarChar, 12, "ZOEKNAAM"))
    '
    'ConnRidderart
    '
    Me.ConnRidderart.ConnectionString = "Provider=PervasiveOLEDB.8.60;Data Source=Thruster Systems;Location=HRP-DC1;Cache " & _
    "Authentication=False;Encrypt Password=False;Mask Password=False;Persist Encrypte" & _
    "d=False;Persist Security Info=False;Impersonation Level=Anonymous;Mode=ReadWrite" & _
    ";Protection Level=None;Auto Translate=False;Port=1583;Pessimistic Read Lock=Fals" & _
    "e;CommandOnly=False;DirectOnly=False;LocalTCP=Fal se"
    '
    'OleDbSelectCommand1
    '
    Me.OleDbSelectCommand1.CommandText = "SELECT ARTIKELNUMMER, ZOEKNAAM FROM ARTIKEL"
    Me.OleDbSelectCommand1.Connection = Me.ConnRidderart
    '
    'OleDbUpdateCommand1
    '
    Me.OleDbUpdateCommand1.CommandText = "UPDATE ARTIKEL SET ARTIKELNUMMER =?, ZOEKNAAM =?"
    Me.OleDbUpdateCommand1.Connection = Me.ConnRidderart
    Me.OleDbUpdateCommand1.Parameters.Add(New System.Data.OleDb.OleDbParameter("ARTIKELNUMMER", System.Data.OleDb.OleDbType.Char, 17, "ARTIKELNUMMER"))
    Me.OleDbUpdateCommand1.Parameters.Add(New System.Data.OleDb.OleDbParameter("ZOEKNAAM", System.Data.OleDb.OleDbType.Char, 12, "ZOEKNAAM"))
    Me.OleDbUpdateCommand1.Parameters.Add(New System.Data.OleDb.OleDbParameter("ARTIKELNUMMER", System.Data.OleDb.OleDbType.Char, 17, System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0, Byte), "ARTIKELNUMMER", System.Data.DataRowVersion.Original, Nothing))
    Me.OleDbUpdateCommand1.Parameters.Add(New System.Data.OleDb.OleDbParameter("ZOEKNAAM", System.Data.OleDb.OleDbType.Char, 12, System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0, Byte), "ZOEKNAAM", System.Data.DataRowVersion.Original, Nothing))
    '
    'DsRidderart
    '
    Me.DsRidderart.DataSetName = "DsRidderart"
    Me.DsRidderart.Locale = New System.Globalization.CultureInfo("nl-NL")
    Me.DsRidderart.Namespace = "http://www.tempuri.org/DsRidderart.xsd"
    '
    'frmUpdatePP
    '
    Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
    Me.ClientSize = New System.Drawing.Size(292, 266)
    Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.btnUpdate, Me.btnMerkcode, Me.txtZoeknaam, Me.txtArtnr})
    Me.Name = "frmUpdatePP"
    Me.Text = "Update Prijslijst Parts"
    CType(Me.DsRidderart, System.ComponentModel.ISupportInitialize).EndInit( )
    Me.ResumeLayout(False)

    End Sub

    #End Region

    Dim keyArtikel(0) As String

    Private Sub btnMerkcode_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnMerkcode.Click

    Dim artnr As String = txtArtnr.Text
    ConnRidderart.Open()
    Dim dt As DataTable = DsRidderart.Tables("ARTIKEL")
    dt.PrimaryKey = New DataColumn() {dt.Columns("ARTIKELNUMMER")}
    DbRidderart.Fill(DsRidderart)
    Dim dr As DataRow
    dr = DsRidderart.Tables("ARTIKEL").Rows.Find(artnr)
    If Not (dr Is Nothing) Then
    txtZoeknaam.Text = dr.Item("ZOEKNAAM")
    Else
    txtZoeknaam.Text = "geen record"
    End If
    ConnRidderart.Close()
    End Sub


    Private Sub btnUpdate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnUpdate.Click

    Dim fndartikel As DataRow
    ConnRidderart.Open()
    DsRidderart.Clear()
    DbRidderart.Fill(DsRidderart)
    Dim mycol(0) As Data.DataColumn
    Dim dt As DataTable = DsRidderart.Tables("ARTIKEL")
    mycol(0) = dt.Columns("ARTIKELNUMMER")
    dt.PrimaryKey = mycol
    keyArtikel(0) = CStr(txtArtnr.Text)
    fndartikel = DsRidderart.Tables("ARTIKEL").Rows.Find(keyArtikel )

    If Not (fndartikel Is Nothing) Then
    fndartikel.Item("ARTIKELNUMMER") = keyArtikel
    fndartikel.Item("ZOEKNAAM") = txtZoeknaam.Text

    DbRidderart.Update(dt)
    ConnRidderart.Close()
    End If

    End Sub


    End Class

  2. #2
    Join Date
    Dec 2001
    Posts
    1,109
    Provided Answers: 4
    Where exactly do you get the error?
    Mirtheil Software
    Certified Pervasive Developer
    Certified Pervasive Technician
    Custom Btrieve/VB development
    http://www.mirtheil.com
    I do not answer questions by email. Please post on the forum.

  3. #3
    Join Date
    Mar 2008
    Location
    Netherlands
    Posts
    18
    Thanx for replying, here's the statement:

    DbRidderart.Update(dt)

  4. #4
    Join Date
    Mar 2008
    Location
    Netherlands
    Posts
    18
    After I changed the Updatecommand statement to:
    Me.OleDbUpdateCommand1.CommandText = "UPDATE ARTIKEL SET ARTIKELNUMMER =?, ZOEKNAAM =? WHERE (ARTIKELNUMMER = ?) AND (ZOEKNAAM = ? OR ? IS NULL AND ZOEKNAAM IS NULL)"

    While execute debugger comes up with:
    System.Data.OleDb.OleDbException: The parameter type must be set before execution (DBPARAMFLAGS_ISINPUT or adParamInput)

  5. #5
    Join Date
    Mar 2008
    Location
    Netherlands
    Posts
    18
    Through the data link configurator i make a oledb connection with a database that has the same name in de PCC. In the Property of this database i read ODBC Engine interface.
    Maybe this is the problem? How can i connect with the original db?

  6. #6
    Join Date
    Mar 2008
    Location
    Netherlands
    Posts
    18
    Problem solved:
    Me.DbRidderart.MissingSchemaAction = System.Data.MissingSchemaAction.AddWithKey

    Me.OleDbUpdateCommand1.CommandText = "UPDATE ARTIKEL SET ARTIKELNUMMER = ?, ZOEKNAAM = ? WHERE (ARTIKELNUMMER = ?)"
    Me.OleDbUpdateCommand1.Connection = Me.ConnRidderart
    Me.OleDbUpdateCommand1.Parameters.Add(New System.Data.OleDb.OleDbParameter("ARTIKELNUMMER", System.Data.OleDb.OleDbType.VarChar, 17, "ARTIKELNUMMER"))
    Me.OleDbUpdateCommand1.Parameters.Add(New System.Data.OleDb.OleDbParameter("ZOEKNAAM", System.Data.OleDb.OleDbType.VarChar, 12, "ZOEKNAAM"))
    Me.OleDbUpdateCommand1.Parameters.Add(New System.Data.OleDb.OleDbParameter("Original_ARTIKEL NUMMER", System.Data.OleDb.OleDbType.VarChar, 17, System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0, Byte), "ARTIKELNUMMER", System.Data.DataRowVersion.Original, Nothing))

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •