|
-
Mar 28th, 2003, 12:51 AM
#1
Thread Starter
Junior Member
simple error
i am trying to loop into the dataset .Here is the vb.net code and error could anybody solve this simple problem
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim cnConnection As OleDbConnection
Dim adAdapter As OleDbDataAdapter
Dim dataset1 As New DataSet()
Dim strConnection As String
Dim strSQL As String
strConnection = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\CAFE\Database\UserDatail.mdb;Persist Security Info=False"
strSQL = "select * from mydata"
cnConnection = New OleDbConnection(strConnection)
adAdapter = New OleDbDataAdapter(strSQL, cnConnection)
adAdapter.Fill(dataset1)
Dim rowfirstName As System.Data.DataRow
'here is the error
For Each rowfirstName In dataset1.Tables("mydata").Rows
Console.WriteLine(rowfirstName("Firstname"))
Next
'error
txtName.Text = dataset1.Tables(0).Rows(0).Item(0)
End Sub
An unhandled exception of type 'System.NullReferenceException' occurred in WindowsApplication1.exe
Additional information: Object reference not set to an instance of an object.
Unhandled Exception: System.NullReferenceException: Object reference not set to an instance of an object.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|