MS Access Error

hisheeraz

Member
Joined
Oct 5, 2008
Messages
11
Programming Experience
1-3
Hello Friends
im having trouble loading data into database into the form
here is my code

VB.NET:
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim Oconn As OleDb.OleDbConnection = New  OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;" & "Data Source=" & Application.StartupPath & "\dbn.mdb")
        Oconn.Open()
        sql = "select aname from tbln"
        da = New OleDb.OleDbDataAdapter(sql, Oconn)
        ds = New DataSet
        da.Fill(ds, "tbln")
        [B]txtname.Text = ds("aname")[/B]
End Sub

im having error at the bold code...
the error is

Error 1 Class 'System.Data.DataSet' cannot be indexed because it has no default property. C:\Documents and Settings\§ RentedLips §\Desktop\VisualBasic2008\Db\Db\Form1.vb 21 24 Db

Please help me!
Thanks
hisheeraz
 

Tom

Well-known member
Joined
Aug 23, 2005
Messages
746
Programming Experience
5-10
Column aname could return multiple rows from the table. You must specifiy the dataset, table name, row within the table and the column to show which field value you want to display in your textbox.

For example

txtname.Text = ds.Tables("tbln").Rows(RowIndexHere).Item("aname").toString
 

cjard

Well-known member
Joined
Apr 25, 2006
Messages
7,052
Programming Experience
10+
Column aname could return multiple rows from the table. You must specifiy the dataset, table name, row within the table and the column to show which field value you want to display in your textbox.

For example

txtname.Text = ds.Tables("tbln").Rows(RowIndexHere).Item("aname").toString

the actual error was caused by a generic dataset having no default property. It is thus an error to say:

Dim myDs as New DataSet
myDs("someTable") <-- there is no property of a dataset that takes a string and returns a DataTable

Saying myDs.Tables("someTable") would not give the error (although, right now the dataset doesnt contain a table of taht name.. thats a different error)
 
Top Bottom