|
.net
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
pass dataset field to an int...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) Show quoteHide quote "RAB" <rabmisso***@yahoo.com> wrote in message news:1157580341.234293.155560@p79g2000cwp.googlegroups.com... >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 > 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> Show quoteHide quote "RAB" <rabmisso***@yahoo.com> wrote in message news:1157580341.234293.155560@p79g2000cwp.googlegroups.com... >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 > 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
Other interesting topics
ASP.NET 2.0: Global.asax code-behind and web deployment project problem
Disco Not Compiling? GridView - RadioButton for survey, idea needed Ignore SqlBulkCopy errors VS 2003 & VS 2005 on one machine Calling aspx page from htm file Column does not belong to table error cannot get value of dropdownlist from postback How to let the user define search filters? Can not add SQLDataAdapter control to toolbox in Visual Web Developer |
|||||||||||||||||||||||