G
Gary Paris
I have enclosed the sample code that I created. I want to read in employee
data, and modify a few fields. I have tried to globally declare the objects
that I need but I still am having problems. I want to update in a seperate
subroutine and seem to have problems. HELP please.
-------------------------------------------
Public Class Form1
Inherits System.Windows.Forms.Form
Public cn As OleDb.OleDbConnection
Public ds As DataSet
Public da As OleDb.OleDbDataAdapter
Public rowEmployee As DataRow
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Try
Dim strConn As String
strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=C:\adonetsbs\SampleDBs\nwind.mdb;"
Dim cn As New OleDb.OleDbConnection(strConn)
Dim strSQL As String
strSQL = "SELECT EmployeeID, FirstName, LastName, Address, City,
Region, " & _
"PostalCode from Employees ORDER BY LastName, FirstName"
Dim da = New OleDb.OleDbDataAdapter(strSQL, strConn)
Dim ds As New DataSet
da.Fill(ds, "Employees")
Dim tbl As DataTable = ds.Tables(0)
'rowEmployee = New DataRow
rowEmployee = tbl.Rows(0)
txtFirstName.Text = rowEmployee("FirstName")
txtLastName.Text = rowEmployee("LastName")
txtAddress.Text = rowEmployee("Address")
Catch ex As Exception
MessageBox.Show(ex.Message & " :: " & ex.Source)
Finally
End Try
End Sub
Private Sub btnUpdate_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnUpdate.Click
Try
rowEmployee("LastName") = txtLastName.Text
da.Update(ds)
Catch ex As Exception
MessageBox.Show(ex.Message & " :: " & ex.Source)
End Try
End Sub
End Class
---------------------------------------
When it runs I get the following error:
"Object reference not set to an instance of an object."
on the da.Update(ds) line in the btnUpdate_Click routine.
HELP.
Thanks,
Gary
data, and modify a few fields. I have tried to globally declare the objects
that I need but I still am having problems. I want to update in a seperate
subroutine and seem to have problems. HELP please.
-------------------------------------------
Public Class Form1
Inherits System.Windows.Forms.Form
Public cn As OleDb.OleDbConnection
Public ds As DataSet
Public da As OleDb.OleDbDataAdapter
Public rowEmployee As DataRow
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Try
Dim strConn As String
strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=C:\adonetsbs\SampleDBs\nwind.mdb;"
Dim cn As New OleDb.OleDbConnection(strConn)
Dim strSQL As String
strSQL = "SELECT EmployeeID, FirstName, LastName, Address, City,
Region, " & _
"PostalCode from Employees ORDER BY LastName, FirstName"
Dim da = New OleDb.OleDbDataAdapter(strSQL, strConn)
Dim ds As New DataSet
da.Fill(ds, "Employees")
Dim tbl As DataTable = ds.Tables(0)
'rowEmployee = New DataRow
rowEmployee = tbl.Rows(0)
txtFirstName.Text = rowEmployee("FirstName")
txtLastName.Text = rowEmployee("LastName")
txtAddress.Text = rowEmployee("Address")
Catch ex As Exception
MessageBox.Show(ex.Message & " :: " & ex.Source)
Finally
End Try
End Sub
Private Sub btnUpdate_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnUpdate.Click
Try
rowEmployee("LastName") = txtLastName.Text
da.Update(ds)
Catch ex As Exception
MessageBox.Show(ex.Message & " :: " & ex.Source)
End Try
End Sub
End Class
---------------------------------------
When it runs I get the following error:
"Object reference not set to an instance of an object."
on the da.Update(ds) line in the btnUpdate_Click routine.
HELP.
Thanks,
Gary