List Info

Thread: RE: In ASP.Net 2 - How to retrieve a single value




RE: In ASP.Net 2 - How to retrieve a single value
country flaguser name
United States
2008-05-21 15:22:30
I'd suggest adding a query to the tableadapter to just return that one value instead of having to use a datatable.
 
In any case, add a test before trying to assign the value, here I'm creating the datatable first, checking for rows and if the value isn't an empty string before trying to set the label:
 
Dim dt As ProductDataSet.GetProductByProductIDDatatable = ProductDataSet.GetProductByProductID(ProductID)
 
If (dt.Rows.Count > 0) AndAlso (dt.Rows(0).Item("ProductName").ToString.Length > 0) Then
   Me.Label2.Text = dt.Rows(0).Item("ProductName").ToString
Else
   ' add error handling code here
End If

Right now you're probably returning an empty string, the assignment for the label is OK ...

tom mallard
   .net web applications
      consumer product design

> Date: Wed, 21 May 2008 16:01:35 -0400
> From: PaoloThecornerStore.com
> Subject: [aspnet] In ASP.Net 2 - How to retrieve a single value
> To: aspnetaspadvice.com
>
> I have a label in a page to which I would like to assign a value.
> I have a ProductXSD file and in it a GetProductByProductIDTable Adapter,
> that works fine (When I test it, and assisgn a value, the correct row is
> returned.
> My VB page looks approximately like this:
>
>
>
> Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
>; Handles Me.Load
> Dim ProductID As Integer = 80 '
> Convert.ToInt32(Request.QueryString("ProductID"))
> Dim ProductDataSet As New
> ProductsTableAdapters.GetProductByProductIDTableAdapter
> Dim myProductName As String =
> ProductDataSet.GetProductByProductID(ProductID).Rows(0)("ProductName").ToStr
> ing
> Label2.Text = myProductName
> End Sub
>
> But I can not get the label2.text to return a value. How do I get
> label2.text to return the value which is in the table column ProductName ?
>
> Thanks,
>
> Paul
>
>
>
>
> --- List Settings ---
> http://aspadvice.com/lists/
>

--- List Settings ---
http://aspadvice.com/lists/
[1]

about | contact  Other archives ( Real Estate discussion Medical topics )