得到的SQL Server数据库中的数据为标签 [英] Get data from SQL Server database into label

查看:120
本文介绍了得到的SQL Server数据库中的数据为标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的ASP.Net的网页,我有一个标签,需要标签的文本是从我的数据库中检索。

In my ASP.Net webpage, I have a label and need the label's text to be retrieved from my database.

我没有问题,写我的数据库,但似乎试图retieve数据又是一个使命...

I have no problem writing to my database, but it seems trying to retieve the data again is a mission...

我需要的是得到从价格列中的数据在我的数据库,从表门票,从哪里 ConcertName 的数据是一样的我的网页的标题,或与我网页相关联串的记录。

What I need is to get the data from the Price column in my database, from the table Tickets, from the record where the ConcertName data is the same as my webpage's title, or a string associated with my webpage.

我试过很多教程了,但一切都只是把我的错误,所以我决定尝试最后一个地方之前,我只是让步,让我的标签是静态的。

I have tried many tutorials already, but all just throw me errors, so I decided to try one last place before I just give in and make my labels static.

在情况下,它可以帮助,我已经试过如下:

In case it helps, I have tried the following:

<一个href=\"http://www.daniweb.com/web-development/aspnet/threads/149283/displaying-data-from-database-to-textbox\"相对=nofollow>第一次尝试

其次尝试

第三次尝试

<一个href=\"http://stackoverflow.com/questions/5792167/how-to-get-data-to-textbox-from-the-database\">Fourth尝试

推荐答案

公司希望使用C#

string MyPageTitle="MyPageTitle"; // your page title here
string myConnectionString = "connectionstring"; //you connectionstring goes here

SqlCommand cmd= new SqlCommand("select Price from Tickets where ConcertName ='" + MyPageTitle.Replace("'","''") + "'" , new SqlConnection(myConnectionString));
cmd.Connection.Open();
labelPrice.Text= cmd.ExecuteScalar().ToString(); // assign to your label
cmd.Connection.Close();

这篇关于得到的SQL Server数据库中的数据为标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆