How do i know field name of my table?

kkhambhalia

New member
Joined
Mar 10, 2006
Messages
1
Programming Experience
3-5
here i am putting my vb.net coding and i fill labels name from table fields name.

Dim MyConn AsNew OleDb.OleDbConnection
Dim mydataset AsNew DataSet

MyConn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Program Files\Microsoft Visual Studio\VB98\nwind.mdb;User Id=admin;Password=;"
MyConn.Open()

Dim myadp AsNew OleDb.OleDbDataAdapter("select * from customers", MyConn)
myadp.Fill(mydataset, "Customers")
Label3.Text = "Total Records : " & mydataset.Tables(1).Rows.Count

Label1.Text = ??????????
Label2.Text = ??????????
TextBox1.Text = mydataset.Tables(0).Rows(0).Item(0)
TextBox2.Text = mydataset.Tables(0).Rows(0).Item(1)


what should i have to write on behalf of ?????????? to fill label with field name?

 
VB.NET:
Label1.text = mydataset.tables(0).columns(0).columnname
Label2.text = mydataset.tables(0).columns(1).columnname
By the way this bit ....

VB.NET:
Label3.Text = "Total Records : " & mydataset.Tables(1).Rows.Count
Should read...

VB.NET:
Label3.Text = "Total Records : " & mydataset.Tables(0).Rows.Count-1

Arrays in vb.net are zero based, so to get a true reading of the number of records you have to minus 1
 
Array indexing is zero-based (element 0 is first item), but count property returns the number of elements.
 
I apologise if i've misunderstood what you have said there johnH but for the purpose of the Total Records in the above exmple it wil be necessary to put -1 after the count method or the number shown won't be the actual number of records in the table, in the way that a human would look at it anyway.
 
Back
Top