pass dataset field to an int...

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
 
B

bruce barker \(sqlwork.com\)

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


-- bruce (sqlwork.com)
 
K

Ken Cox [Microsoft MVP]

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>
 
R

RAB

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,598
Members
45,150
Latest member
MakersCBDReviews
Top