pass dataset field to an int...

  • Thread starter Thread starter RAB
  • Start date Start date
R

RAB

I have filled a dataset with the following code in VB...

......
dim DataSet as System.Data.DataSet = new System.Data.DataSet
dataAdapter.Fill (dataSet)

dim MyInt as integer


I want to pass an integer field in my dataset to MyInt
but can't quite figure it out.

Any help would be appreciated.

Thanks,
RABMissouri2006
 
in the dataset pick the table, row and column that contains the int value.
see docs.


-- bruce (sqlwork.com)
 
Hi RAB,

Assuming you know what row you are getting the value from, you can use the
code below.

Let us know if this helps?

Ken
Microsoft MVP [ASP.NET]

<%@ page language="VB" %>

<%@ import namespace="system.data" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">
Private Sub Page_Load _
(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
' From Ken Cox Microsoft MVP [ASP.NET]
' Create a dataset
Dim ds As New DataSet
' Add a table to the dataset
ds.Tables.Add(CreateDataSource())
Dim MyInt As Integer

MyInt = DataBinder.Eval(ds, _
"Tables(0).DefaultView(0).AnIntegerValue")
' Bind everything on the page
Page.DataBind()
Response.Write(MyInt.ToString)
End Sub


Function CreateDataSource() As Data.DataTable
Dim dt As New Data.DataTable
Dim dr As Data.DataRow
dt.Columns.Add(New Data.DataColumn _
("AnIntegerValue", GetType(Int32)))
dt.Columns.Add(New Data.DataColumn _
("StringValue", GetType(String)))
dt.Columns.Add(New Data.DataColumn _
("CurrencyValue", GetType(Double)))
dt.Columns.Add(New Data.DataColumn _
("Boolean", GetType(Boolean)))
Dim i As Integer
For i = 5 To 15
dr = dt.NewRow()
dr(0) = i
dr(1) = "Item " + i.ToString()
dr(2) = 1.23 * (i + 1)
dr(3) = (i = 4)
dt.Rows.Add(dr)
Next i
Return dt
End Function
</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>Bind to a Variable</title>
</head>
<body>
<form id="form1" runat="server">
<div>
</div>
</form>
</body>
</html>
 
Thanks for your help Ken,

Here is the code you shared that applies to me...

Dim MyInt As Integer

MyInt = DataBinder.Eval(ds, _
"Tables(0).DefaultView(0).AnIntegerValue")
' Bind everything on the page
Page.DataBind()
Response.Write(MyInt.ToString)

In my case I am populating my DataSet with an Acess Database. If I
have 3 tables (table1, table2, table3). In table2 I have 2 columns A
and B. B is an 'int' (which I am interested in) How would I write
the above line of code that applies to my situation?

MyInt = DataBinder.Eval(ds, .....?

Thanks,
RABMissouri2006
 
Back
Top