Welcome to the dBforums forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions, articles and access our other FREE features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload your own photos and access many other special features. Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact contact support.

If you prefer not to see double-underlined words and corresponding ads, place your cursor
here for ContentLink opt out.

Go Back  dBforums > Database Server Software > Pervasive.SQL > Problem updating records Pervasive db.

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 03-18-08, 12:54
Keereweer Keereweer is offline
Registered User
 
Join Date: Mar 2008
Posts: 9
Unhappy 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
Reply With Quote
  #2 (permalink)  
Old 03-18-08, 12:59
mirtheil mirtheil is offline
Registered User
 
Join Date: Dec 2001
Posts: 813
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.
Reply With Quote
  #3 (permalink)  
Old 03-18-08, 13:07
Keereweer Keereweer is offline
Registered User
 
Join Date: Mar 2008
Posts: 9
Thanx for replying, here's the statement:

DbRidderart.Update(dt)
Reply With Quote
  #4 (permalink)  
Old 03-19-08, 05:29
Keereweer Keereweer is offline
Registered User
 
Join Date: Mar 2008
Posts: 9
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)
Reply With Quote
  #5 (permalink)  
Old 03-19-08, 13:00
Keereweer Keereweer is offline
Registered User
 
Join Date: Mar 2008
Posts: 9
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?
Reply With Quote
  #6 (permalink)  
Old 03-21-08, 06:40
Keereweer Keereweer is offline
Registered User
 
Join Date: Mar 2008
Posts: 9
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))
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On