如题就是一个小小的绑定Label控件,把前后台的关键代码发给我看看吧
Label1.Text=ds.Tables[0].Rows[0][0].ToString();
这三个0我该怎么写啊
@jinggege: 谁知道你想绑定哪个数据。。。
@顾晓北: 就写绑定的数据字段吗?是三个都要换吗?哥哥说下,谢谢了
@jinggege: Label1.Text=ds.Tables[0].Rows[你的第几行数据][数据的列,可以写列名,可以用索引].ToString();
@jinggege: 根据你这个查询,第一个应该不用改,就Tables[0]就行了。
前台Label有一个Id,后台直接Lab.Text="xxx" 。WebForms。
help.openConnection();
DataSet ds = new DataSet();
string sql = "select Title,Dody,DateTime from News where NewsID=Newsid";
SqlDataAdapter sda = new SqlDataAdapter(sql, help.Connection);
sda.Fill(ds);
PagedDataSource pds = new PagedDataSource();
pds.DataSource = ds.Tables[0].DefaultView;
xxx该是什么值啊。说详细点,怎么返回sql语句中的数据啊
@jinggege: xxx代表一个string,反正只要是string类型的数据就可以绑定。数据库出来的结果,你也要取出其中的一个string才行。
using System.Data;//添加命名空间
using System.DataSqlClient;
public void FillDisCus( string IDD)
{
string _sqql = "select *(或者列名)
from TableName";
DataRow dr = ExecuteDataSet(_sqql).Tables[0].Rows[0];
lable1.Text = dr["字段名"].ToString();
lable2.Text = dr["字段名"].ToString();
ExecuteDataSet:填充数据集的方法,还有连接数据库的语句你应该会吧?
help.openConnection();
DataSet ds = new DataSet();
string sql = "select Title,Dody,DateTime from News where NewsID=Newsid";
SqlDataAdapter pds = new SqlDataAdapter(sql, help.Connection);
pds.Fill(ds);
是这样么,后面怎么写
@jinggege: 我全部的写给你
using System.Data;//添加命名空间
using System.DataSqlClient;
SqlConnection coon = new SqlConnection();
coon.ConnectionString = "server=LocalHost;DataBase=Customer;User ID=qwe;Password=123456";
coon.Open();
SqlCommand cmd = new SqlCommand();
cmd.Connection = coon;
cmd.CommandType = CommandType.Text;
cmd.CommandText = _Ssql;
SqlDataAdapter sda = new SqlDataAdapter();
sda.SelectCommand = cmd;
DataRow dr = sda.Fill(_sqql).Tables[0].Rows[0];
lable1.Text = dr["字段名"].ToString();
lable2.Text = dr["字段名"].ToString();
你试试,弄不出来加我QQ:30119459我下了
Text=<%=后台的变量%>
help.openConnection();
DataSet ds = new DataSet();
string sql = "select Title,Dody,DateTime from News where NewsID=Newsid";
SqlDataAdapter pds = new SqlDataAdapter(sql, help.Connection);
pds.Fill(ds);
后台怎么写,