Link to home
Start Free TrialLog in
Avatar of fredstov
fredstov

asked on

Working with data tables

I am creating a datatable.  I want to read using a select statement. I then want to be able to move data out of a column by using the column name into a field dimmed as string.  I have the table loaded with data.  I have included the code and what I am trying to do which doesn't work.
Dim PRates As New System.Data.DataTable("HoldRates")

PRates.Columns.Add("Prodnb", Type.GetType("System.String"))
PRates.Columns.Add("mem", Type.GetType("System.Double"))
PRates.Columns.Add("sp", Type.GetType("System.Double"))
PRates.Columns.Add("child", Type.GetType("System.Double"))
PRates.Columns.Add("fam", Type.GetType("System.Double"))
PRates.Columns.Add("pfactor", Type.GetType("System.Double"))

Do While rdr.Read() = True
PRates.Rows.Add()
PRates.Rows(PRates.Rows.Count - 1)("ProdNb") = rdr("prodnb")
PRates.Rows(PRates.Rows.Count - 1)("mem") = rdr("Employee")
PRates.Rows(PRates.Rows.Count - 1)("sp") = rdr("Spouse")
PRates.Rows(PRates.Rows.Count - 1)("child") = rdr("Children")
PRates.Rows(PRates.Rows.Count - 1)("fam") = rdr("Family")
PRates.Rows(PRates.Rows.Count - 1)("PFactor") = rdr("ratefactor")
Loop
Session("prodtable") = PRates
''** the following reads the table
Dim ratetable As System.Data.DataTable = Session("prodtable")
Dim dro() As System.Data.DataRow = ratetable.Select("prodnb = '100'") 'this gives syntax error
Dim tmp As String
tmp = dro("mem").ToString()

dro("mem") = "123"

Open in new window

Avatar of Reza Rad
Reza Rad
Flag of New Zealand image

what is the error you received?

Avatar of fredstov
fredstov

ASKER

the command
tmp = dro("mem").tostring()  says it cant convert integer to string.

All I want to know is the syntax to move  data in and out of the columns by column name on the row that is found in the select statement. line number 24 and 26 don't work.

Hope that helps
ASKER CERTIFIED SOLUTION
Avatar of appari
appari
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial