Just trying to do a simple command...

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi

I am just trying to do a simple command like taking a data field from a database at load time. It does not work. I have the following code

Dim rowY As DataRo
Dim strMachine_Name As Strin

MyClass.OleDbDataAdapter1.Fill(MyClass.DataSet11

strMachine_Name = rowY("Machine_Name"

'Shouldnt strMachine_Name take the name of the data in that particular field in the database? After this I would then like to put strMachine_Name to a text box

Thanks
Ros
 
Ross:

You haven't specified a row index so it's not going to work unless you
specified rowY with an index beforehand. Let's say that you wanted to
access the first row in the table, and the Column is Machine_Name (for this
example, I'm going to assume the columnIndex is 1)

strMachine_Name = DataSet11.Tables(0).Rows(0)(1)

If it was the second row you'd replace it with Rows(1)(1).

You could also do it with Rows(0)("Machine_Name")

Either will work but if you want performance, reference your Column names
with a numeric index so it doesn't have to resolve the name at each pass. If
you are only referencing one row the difference will be minimal, but if you
are walking a large datatable, the difference can get quite big. YOu can
use an Enum (Bill Vaughn's cool method) and give each index a Readable name
(matching to ColumnName for instance) so you can have the best of both
worlds.
HTH,

Bill
Ross said:
Hi,

I am just trying to do a simple command like taking a data field from
a database at load time. It does not work. I have the following code.
Dim rowY As DataRow
Dim strMachine_Name As String

MyClass.OleDbDataAdapter1.Fill(MyClass.DataSet11)

strMachine_Name = rowY("Machine_Name")

'Shouldnt strMachine_Name take the name of the data in that particular
field in the database? After this I would then like to put strMachine_Name
to a text box,
 
Back
Top