data adapter update method won't work

Please support our VB.NET advertiser: Intel Parallel Studio Home
Reply

Join Date: Oct 2005
Posts: 33
Reputation: SethR is an unknown quantity at this point 
Solved Threads: 1
SethR SethR is offline Offline
Light Poster

data adapter update method won't work

 
0
  #1
Sep 19th, 2006
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
Reply With Quote Quick reply to this message  
Join Date: Aug 2006
Posts: 57
Reputation: Exelio is an unknown quantity at this point 
Solved Threads: 0
Exelio Exelio is offline Offline
Junior Poster in Training

Re: data adapter update method won't work

 
0
  #2
Sep 20th, 2006
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
Reply With Quote Quick reply to this message  
Join Date: Oct 2005
Posts: 33
Reputation: SethR is an unknown quantity at this point 
Solved Threads: 1
SethR SethR is offline Offline
Light Poster

Re: data adapter update method won't work

 
0
  #3
Sep 20th, 2006
Thank you....I will try you're changes as soon as I get back from work....
Reply With Quote Quick reply to this message  
Join Date: Oct 2005
Posts: 33
Reputation: SethR is an unknown quantity at this point 
Solved Threads: 1
SethR SethR is offline Offline
Light Poster

Re: data adapter update method won't work

 
0
  #4
Sep 20th, 2006
It's not working.....I'm using an Access database so I can use a sqlcommand builder.
Reply With Quote Quick reply to this message  
Join Date: Aug 2006
Posts: 57
Reputation: Exelio is an unknown quantity at this point 
Solved Threads: 0
Exelio Exelio is offline Offline
Junior Poster in Training

Re: data adapter update method won't work

 
0
  #5
Sep 25th, 2006
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.
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 13
Reputation: chan_lemo is an unknown quantity at this point 
Solved Threads: 1
chan_lemo chan_lemo is offline Offline
Newbie Poster

Re: data adapter update method won't work

 
0
  #6
Nov 3rd, 2008
Try the follwoing link , it explin DataAdapter.Update method.

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

lemo.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the VB.NET Forum
Thread Tools Search this Thread



Tag cloud for VB.NET
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC