.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
david stephan
Gaurav Pal
Post New Web Links

Assigning values from a Database to a Label

Posted By:      Posted Date: September 30, 2010    Points: 0   Category :ASP.Net


I want to select all the values from a table in my database and then put each value in order into labels that are on the asp page.

I can Select all the values from that database fine but I am rather stuck as how to put the values into the individual labels? Here is the code I have connecting to my database.

  Dim cmd As New SqlCommand
            Dim myConnection As New SqlConnection("Data Source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\Alerts.mdf;User Instance=true")

            cmd.Connection = myConnection
            cmd.CommandText = "SELECT DateTime, Description FROM EmailTemplateLoad"


        Catch ex As Exception

        End Try

How can I put the DateTime value into Label1 and the Decription into Label2??

I have had a nose about but can't seem to find the information I need.

Any pointers greatly appreciated.

View Complete Post

More Related Resource Links

accessing values from a database with datalist?


I have a datalist and I am filling it using a dataadapter, dataset. So in my .ascx page, I have

<asp:datalist runat="server" id="dlProducts" repeatcolumns="2" repeatdirection="horizontal">


<table border="0">

<tr><td><%# Eval("Item_Name") %></td></tr>

<tr><td>I have to add a picture here</td><td><%# Eval("First_Name") %></td></tr>




In the area where I have put a statement like "I have to add a picture here", I have write a big case statement.  Like:

Case: 6 // show a picture from file1

case: 7 // show a picture from file2

Case 8: //show a picture from file3


So How do I do this here?  Because I dont know how to access the datalist values from code behind.


Here is my code behind:

SQLString = "SELECT First_Name, Picture, item_name, item_id from table1 where item_id = " + request.querystring["iid"];

dataadapter daItems = new dataadapter(SQLString, "connection_name");

dataset dsItems = new dataset();



Help with updating database with values from Repeater control using c#


Hello, I'm new to ASP.NET 3.5 with C#. I really need some help.

I used a Repeater control to create a simple (editable) list where, when a user logs in, they can edit their list of expenses.  The ASP page works fine.

 My issue is with the code-behind.  I am really confused with how to extract the values from the repeater control. The FindControl method does not seem to be working.  Also, the code I am using resets my 'Amount' values back to 0.00. (0.00 is the amount the user sees when they first encounter the page).

 Here's a portion of the code on the ASP page:

<asp:Repeater ID="Repeater1" runat="server" DataSourceID="SqlDataSource1"





<td><asp:Label ID="lblExpId" runat="server"  Text='<%# Bind("ExpId") %>'></asp:Label> </td>

 <td><asp:Textbox ID="lblExpense" runat="server" Width= "190px" Text='<%# Bind("ExpenseName") %>'></asp:Textbox> </td>

 <td><asp:Textbox ID="txtAmount" runat="server" Width= "100px"

How to stored values 10.57 into database



I have the variable value 10.57
10.57 If I write, it stores data: 1057.00

 I need 10.57 into database


Writing values back to a database

Hi All, I'm trying to write values back to an access database from an open source mathematical programming language (called glpk) using ODBC. I succeeded in doing so in most variables except one. The problem is described below: The following code gets an error when writing the data: \begin code:   table x3_iii {j in TF, k in C, p in P, t in T: x3[j,k,p,t]>0} OUT 'ODBC'   'FileDSN=.\d2.dsn'   'UPDATE ((Channels a INNER JOIN ChannelPeriodProducts b' 'ON a.ChannelID = b.ChannelID)' 'INNER JOIN TransformerTypes d' 'on a.OriginFacilityID = d.FacilityID' 'SET b.Quantity = ?'   'WHERE d.TransformerTypeID = ?'   'AND a.OriginFacilityID =?'   '    AND b.ProductID = ?'   '    AND b.PeriodID = ?':   x3[j, k, p, t], j, k, p, t; \end code Note that the sql is on multiple lines, because of a maximum strings limit in the glpk (but the way I used in the code is fine and worked without problems for writing other variables). Now, let me describe what I am basically trying to do: I'm trying to write the values for the variable x3[j,k,p,t] in its field "Quantity" in the table 'ChannelPeriodProducts'. The indices for that variable are j,k,p,t. The 'ChannelPeriodProducts' table has a "ChannelID", "PeriodID", "ProductID" and "Quantity" field

Any way to pass Multiple Values for a single Label in the Parameter?

  I have a Report that Contains 2 Parameters, @Customer & @Area. When trying to set up the Available Values for @Area, I'm having issues using multiple values for one Label, i.e. = "4006" Or "4610" One of the Filters in the Report is an Operation number, which is the [OPERATION] field, which is setup as a filter on the Tablix referencing the @Area parameter.  PROBLEM: I cannot retrieve any data when trying to use the ‘Or’ Operator here. If I simply put “4006” or “4610” I retrieve data, but when trying to combine it returns no data. Example, I need to allow a user to select ‘Chassis Incoming’, which would include data from Operations 4006 & 4610. QUESTION: Any way to pass Multiple Values for a single Label in the Parameter? I realize the typical solution may be to use ‘Multi-Value’ selection, but in this case we want the User to select the Area and the multiple values for Filtering will be automatically determined for them. Otherwise, they are subject to not getting it correct. I have tried several different ways, such as =”4006” Or “4610”, =(“4006”, “4610”), = In(“4006”, “4610”), etc….   Note: We are using Report Builder 3.0  

Save temporary values in gridview to database

Hi.I have a code here,where it will store temporary data in a gridview from textbox where when the data is stored temporarily in gridview.Alternately,it will be linked to search the word in google.Now i want to save the values in the gridview to database.I m new to asp.net,seeking ideas from all.Any ideas guys?Here is my .aspx code: <body> <div> <table > <tr> <td class="style1"> <asp:Label ID="Label1" runat="server" Text="Caller Info :"></asp:Label> </td> <td style="width: 100px"> <asp:TextBox ID="TxtName" runat="server" class="cls" onekeypress="" ToolTip="Press Enter key for new input"></asp:TextBox> </td> </tr> </table> <asp:Button ID="BtnAddToTable" runat="server" align="right" class="cls" Text="Add" OnClick="BtnAddToTable_Click" /> <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" > <Columns> <asp:TemplateField HeaderText="Caller Information"> <ItemTemplate> <a onclick='document.getElementById("<%=iframe1.ClientID%>").src = this.href; return false

Dynamically Generate No of Control(like Label) depend upon database no of item


I have a requirment like 

i required a dynamically generated Control (like Label) depend upon Database no of item


  If i fetch Database text (like Name) fieldd 3 time than i am intrested to generate  label 3 time

for (int i=0;i<table.row.count;i++)


label label[i]=table.row[i][0].Tostring();


How can do the above because label[i] is not allowed

Khurram Shahzad

Get list of Correlation Key Values from Database


I want to know from the the Sql database (workflow persisted) how I can get a list of the unique ids I have correlating to the workflows started.  I have no problem getting the system generated Workflow Instance Id GUIDs, however I want to display our OrderId instead.

My Info

-Using Workflow 4.0

-Workflows are getting persisted to database

-correlation handle is set to my unique Id (OrderId) in the ReceiveActivity

Label of parameter = values of 2 fields



I would like to create a parameter that has as value, the combination of 2 fields of my dataset.
Say like Name and FirstName combined as EmployeeName
There is no chance I can update/change the procedure that delivers these fields.

I tried looking into the code, but didn't have a lot of success.
Anyone some ideas?


dropdown list wont populate values from database


Hello everyone i need help. Ive been having this problem for almost  3 days now. dropdown list won't populate from database

Below is the code i am using:

<%@ Page Title="" Language="VB" MasterPageFile="~/Site.master" AutoEventWireup="false" CodeFile="PhotoAlbum.aspx.vb" Inherits="PhotoAlbum" %>

<asp:SqlDataSource ID="categoriesDataSource" runat="server"  
<%$ ConnectionStrings:ConnectionString %>"  
    SelectCommand="SELECT [CategoryID], [Name] FROM [Categories] WHERE ([UserId] = @UserId) ORDER BY [Name]"> 
<asp:QueryStringParameter Name="UserId" QueryStringField="ID"/> 

load new page and populate the values without database



I'm creating a website of 5 pages using c# (asp.net).

How do i link 2 pages, ie., on click of a button on first page should take me to second page.

Advance thanks,


assigning database roles with smo (C#)


Hi All,

I'm using VS C# express with SQL 2005 express.

I have the following problem:

I would like to assign database roles in a given database for a login by using smo. Let's say:

I have a Login, created with smo named MyLogin and a database name MyDatabase.

How can I map MyLogin to MyDatabase and give for example db_datawriter database role membership for it, using SMO?

I do not find the way, propably I miss something...

Any help is highly appreciated, I would be thanksfull if one could give a code example to solve this.




How to read PDF using Asp.net(C#.net) and store values in Database


Dear All,

Please try to guide me how to achieve this one. my application need to do reading the PDF document and want to store the values in Database.

Actually what happens is my customers sends me the OCR scanned copied in the form of PDF file. i need to read those scanned pdf files and store the customer information into my  table.

please try to help me how to do this..

Thanking uou,



Copy table values from one database to another


Dear All,

I am stuck with an issue. I have around 200 rows in a table with a particular database. I want to copy those values to another table in a different database.

Pls support

XML with PrimaryKey values to delete rows in database table at a time



I'm having a gridview in my aspx page with checkbox, User can select one or more than one record(s) at a time and clicks on delete button, Then i'm constructing an object of my DTO and adding all the checked row's Primary Key (DataKeyNames - GUID's in my case) to a serializable class and generating an XML and sending it as parameter to the Stored Procedure.

My Doubt is, can i bulk delete all the rows from database table those are present in my XML document??

If it works, I can do bulk update with XML only, i already did bulk insertion by generating an XML..

My Another Question is, Will it affect the performance? Each time when i construct an DTO object and adding it to the Generic List??

WHich one is better, I mean ObjectDataSource or SQLDataSource or my XML method??

Can anyone please help me out clarifying my doubts and also XML Delete Query..


My XML will be like this











Will bulk delete happen in the above case?



Assigning values programmatically to Taxonomy Web Tagging Control


I am trying to develop a custom field in a list that will allow selection from entire Term Store. Fortunately I learned about TaxonomyWebTagging control and its ability to allow selection from multipe termsets when used programmatically.

I am developing a custom field type that allows selection from multiple termsets using this control. The field type works fine when adding or displaying the terms. It however breaks when Editing. When values are assigned to the TaxonomyWebTagging control (on server side), it gives an error on client that "There was an error processign the request". (in a dialog box). No exception is raised on the server side.

I have made sure that value assigned are in correct format to the control.

There is no problem with the connection of control to metadata term store as when I cancel the dialog and start typing in the control, it resolves the term store values.

Any insight how to assign values in TaxonomyWebTagging Control will be highly appreciated.



Sharepoint Architect - NY, USA

How to show readonly values in textbox from database?


I have 4 textboxes. On which I want to show values from a database table which are readonly. After a button click event I have to show the updated values again.Two difficulties I have faced 1st to get four fields of data from DB than show those four data in specific texboxes.another is after doing some calculation showing updated data after a button click event. Can anyone give me a solution?

ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend