Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Assign a value to a Label from a database

Status
Not open for further replies.

wallaceoc80

Programmer
Jul 7, 2004
182
GB
Here is a snippet of code that I use to query my database in ASP.NET

Code:
string query = "Select F.AppID, F.FAQID, F.FAQ, F.Criticality";
				query += " from FAQ F, Application A";
				query += " where F.AppID = A.AppID";
				query += " AND F.AppID = " + selectedAppID;
				query += " AND F.FAQ LIKE '%" + keyword + "%'";
			
			try
			{
				SqlDataAdapter dataAdapter = new SqlDataAdapter(query, strConnection);

				searchData = new DataSet();
				dataAdapter.Fill(searchData);

				string query2 = "Select GripsID";
					query2 += " from Application";
					query2 += " where appID = " + keyword;

				
				conn.Dispose();
			}

I then go on to bind the resulting data to a DataGrid.

What I also want to do is query the Database for a single value. I want to query one of the above Tables (Application) to retrieve the value of one column for a row meeting the condition I provide. I then want to set the value of a Label to the value returned from the Database.

How do I go about this? Do I still use a Dataset when I'm only getting one value and I'm not binding it to a DataGrid?

Any ideas would be appreciated.

Regards,

Wallace
 
Surely it's just a simple case as follows :
Set up the SQL as needed, create an SqlCommand and then run an ExecuteScalar against it to get the value - set this to be the Text against the label.
I hope that this helps.
Steve
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top