944,033 Members | Top Members by Rank

Ad:
  • VB.NET Discussion Thread
  • Unsolved
  • Views: 14372
  • VB.NET RSS
Sep 19th, 2006
0

data adapter update method won't work

Expand Post »
Someone please help me before I smash my computer.


Every time I try to update a database using my data adapters update method I get the following error.....Object variable or With block variable not set.

I can't for the life of me figure out why this is happening. Here's the code if anyone cares to look.


Public Class Form1

Inherits System.Windows.Forms.Form
Dim conService As String
Dim currpath As String = System.Environment.CurrentDirectory
Dim sqlStr As String
Dim sqlStr2 As String
Dim serviceDT As New DataTable
Dim serviceDS As New DataSet
Public daService
Dim daStatus
Dim rowIndx As Integer
Dim currMan As CurrencyManager

Dim cbServiceCalls As New System.Data.OleDb.OleDbCommandBuilder

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
conService = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source= " & currpath & "\ServiceCalls.mdb"
sqlStr = "Select * from ServiceCalls "
sqlStr2 = "Select * from ServiceStatus"
Dim daService As New OleDb.OleDbDataAdapter(sqlStr, conService)
Dim daStatus As New OleDb.OleDbDataAdapter(sqlStr2, conService)
daService.Fill(serviceDT)
daService.Fill(serviceDS, "ServiceCalls")
daStatus.Fill(serviceDS, "ServiceStatus")
DataGrid1.DataSource = serviceDS.Tables("ServiceCalls")
DataGrid2.DataSource = serviceDS.Tables("ServiceStatus")

currMan = Me.BindingContext(serviceDS, "ServiceCalls")


daService.Dispose()
FillTextBoxes()

Sub FillTextBoxes()
txtSerOrdNum.Text = CInt(serviceDT.Rows(rowIndx)("ServiceOrdNum"))
txtCustId.Text = CInt(serviceDT.Rows(rowIndx)("CustomerID#"))
txtReceived.Text = CStr(serviceDT.Rows(rowIndx)("CallReceivedOn"))
txtMachine.Text = CStr(serviceDT.Rows(rowIndx)("MachineModel"))
txtSerial.Text = CInt(serviceDT.Rows(rowIndx)("SerialNum"))
txtProblem.Text = CStr(serviceDT.Rows(rowIndx)("ProblemDescription"))
txtTech.Text = CStr(serviceDT.Rows(rowIndx)("AssignedTech"))


End Sub

Private Sub btnNext_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNext.Click
If rowIndx < serviceDT.Rows.Count - 1 Then
rowIndx = rowIndx + 1
FillTextBoxes()
Else
rowIndx = 0
FillTextBoxes()
End If

End Sub

Private Sub btnADDds_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnADDds.Click
Dim newRec As DataRow
newRec = serviceDS.Tables("ServiceCalls").NewRow()
newRec("ServiceOrdNum") = InputBox("Enter service order number", "newRec")
newRec("CustomerID#") = InputBox("Enter the customer id number", "newRec")
newRec("CallReceivedOn") = InputBox("Enter call entry date", "newRec")
newRec("MachineModel") = InputBox("Enter the machine model", "newRec")
newRec("SerialNum") = InputBox("Enter the serial number", "newRec")
newRec("ProblemDescription") = InputBox("Enter the problem description", "newRec")
newRec("AssignedTech") = InputBox("Enter the assigned tech", "newRec")
serviceDS.Tables("ServiceCalls").Rows.Add(newRec)


End Sub

Private Sub btnADDdb_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnADDdb.Click



daService.Update(serviceDS)<<<<FAILS HERE:mad:


End Sub
End Class
Similar Threads
Reputation Points: 10
Solved Threads: 1
Light Poster
SethR is offline Offline
33 posts
since Oct 2005
Sep 20th, 2006
0

Re: data adapter update method won't work

hi seth,

Looks like u r really frustated.U need to make slight changes in the code. Below is the code with the changes.

Dim conService As New SqlConnection("ur path")
Dim currpath As String = System.Environment.CurrentDirectory
Dim sqlStr As String
Dim sqlStr2 As String
Dim serviceDT As New DataTable
Dim serviceDS As New DataSet
Dim daService, daStatus As New SqlDataAdapter
Dim rowIndx As Integer
Dim currMan As CurrencyManager

PrivateSub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) HandlesMyBase.Load
sqlStr = "Select * from <table1>"
sqlStr2 = "Select * from <table2>"
daService.SelectCommand = New SqlCommand(sqlStr, conService)
Dim cbServiceCalls As New SqlCommandBuilder(daService)
daStatus.SelectCommand = New SqlCommand(sqlStr2, conService)
conService.Open()
daService.Fill(serviceDT)
daService.Fill(serviceDS, "<table1>")
daStatus.Fill(serviceDS, "<table2>")
DataGrid1.DataSource = serviceDS.Tables("<table1>")
DataGrid2.DataSource = serviceDS.Tables("("<table2>")
currMan = Me.BindingContext(serviceDS, "<table1>")
FillTextBoxes()
End Sub

Sub FillTextBoxes()
txtSerOrdNum.Text = CInt(serviceDT.Rows(rowIndx)("ServiceOrdNum"))
txtCustId.Text = CInt(serviceDT.Rows(rowIndx)("CustomerID#"))
txtReceived.Text = CStr(serviceDT.Rows(rowIndx)("CallReceivedOn"))
txtMachine.Text = CStr(serviceDT.Rows(rowIndx)("MachineModel"))
txtSerial.Text = CInt(serviceDT.Rows(rowIndx)("SerialNum"))
txtProblem.Text = CStr(serviceDT.Rows(rowIndx)("ProblemDescription"))
txtTech.Text = CStr(serviceDT.Rows(rowIndx)("AssignedTech"))


End Sub

Private Sub btnNext_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNext.Click
If rowIndx < serviceDT.Rows.Count - 1 Then
rowIndx = rowIndx + 1
FillTextBoxes()
Else
rowIndx = 0
FillTextBoxes()
End If

End Sub


Private Sub btnADDds_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnADDds.Click
Dim newRec As DataRow
newRec = serviceDS.Tables("ServiceCalls").NewRow()
newRec("ServiceOrdNum") = InputBox("Enter service order number", "newRec")
newRec("CustomerID#") = InputBox("Enter the customer id number", "newRec")
newRec("CallReceivedOn") = InputBox("Enter call entry date", "newRec")
newRec("MachineModel") = InputBox("Enter the machine model", "newRec")
newRec("SerialNum") = InputBox("Enter the serial number", "newRec")
newRec("ProblemDescription") = InputBox("Enter the problem description", "newRec")
newRec("AssignedTech") = InputBox("Enter the assigned tech", "newRec")
serviceDS.Tables("ServiceCalls").Rows.Add(newRec)
End Sub

Private Sub btnADDdb_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnADDdb.Click
daService.Update(serviceDS, "maintable")
daService.Dispose()
MsgBox("Updated", MsgBoxStyle.Information)
End Sub

Hope this helps.

Thanks and regards

Exelio
Reputation Points: 10
Solved Threads: 0
Junior Poster in Training
Exelio is offline Offline
57 posts
since Aug 2006
Sep 20th, 2006
0

Re: data adapter update method won't work

Thank you....I will try you're changes as soon as I get back from work....
Reputation Points: 10
Solved Threads: 1
Light Poster
SethR is offline Offline
33 posts
since Oct 2005
Sep 20th, 2006
0

Re: data adapter update method won't work

It's not working.....I'm using an Access database so I can use a sqlcommand builder.
Reputation Points: 10
Solved Threads: 1
Light Poster
SethR is offline Offline
33 posts
since Oct 2005
Sep 25th, 2006
0

Re: data adapter update method won't work

hi seth,

I have tried the same coding with access too and i dont seem to have a problem.

Check ur provider path again.
Jet OLEDB:Global Partial Bulk Ops=2;Jet OLEDB:Registry Path=;Jet OLEDBatabase Locking Mode=0;Data Source=<ur mdb path>;Jet OLEDB:Engine Type=5;Provider=Microsoft.Jet.OLEDB.4.0;Jet OLEDBystem database=;Jet OLEDBFP=False;persist security info=False;Extended Properties=;Mode=Share Deny None;Jet OLEDB:Encrypt Database=False;Jet OLEDB:Create System Database=False;Jet OLEDBon't Copy Locale on Compact=False;Jet OLEDB:Compact Without Replica Repair=False;User ID=Admin;Jet OLEDB:Global Bulk Transactions=1


When u r using access,use OledbCommandBuilder and not sqlcommandBuilder.

Can u tell me exactly what kind of error u get?

Thanks

Regards

Exelio
Last edited by Exelio; Sep 25th, 2006 at 3:19 am.
Reputation Points: 10
Solved Threads: 0
Junior Poster in Training
Exelio is offline Offline
57 posts
since Aug 2006
Nov 3rd, 2008
0

Re: data adapter update method won't work

Try the follwoing link , it explin DataAdapter.Update method.

http://vb.net-informations.com/dataa...-sqlserver.htm

lemo.
Reputation Points: 10
Solved Threads: 1
Newbie Poster
chan_lemo is offline Offline
17 posts
since Oct 2008
Aug 7th, 2010
0
Re: data adapter update method won't work
hullo, i have tried to use the update property in access but it has failed to work out i get this error syntax UPDATE .please help me
Reputation Points: 10
Solved Threads: 0
Newbie Poster
reenez is offline Offline
1 posts
since Jun 2010

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in VB.NET Forum Timeline: Help in Calculation coding
Next Thread in VB.NET Forum Timeline: Slow problem





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC