直接绑定数据库里的数据 不用控件

来源:百度知道 编辑:UC知道 时间:2024/05/12 11:57:32
public string Name;
protected void Page_Load(object sender, EventArgs e)
{
SqlConnection sqlcon = new SqlConnection("Data Source=007-324a07be4d8;Initial Catalog=db_ac;Integrated Security=SSPI;user ID=;PWD=;");
string sqltopadcom = "select * from tb_news where news_id='1' ";
SqlDataAdapter myda = new SqlDataAdapter(sqltopadcom, sqlcon);
Name =
Page.DataBind();
}

前台 <%=Name%>

哪个Name应该怎样写 前台才能显示数据啊 前台就如 <div>内容:(这里就显示数据) </div> 谢谢各位啦

1、<%#Name%>
2、<%# Eval("Name")%>

protected void Page_Load(object sender, EventArgs e)
{
SqlConnection sqlcon = new SqlConnection("Data Source=007-324a07be4d8;Initial Catalog=db_ac;Integrated Security=SSPI;user ID=;PWD=;");
string sqltopadcom = "select * from tb_news where news_id='1' ";
SqlDataAdapter myda = new SqlDataAdapter(sqltopadcom, sqlcon);
dataset ds=new dataset();
myda.fill(ds)
Name =ds.Tables[0].Rows[0]["name"].ToString();
}

SqlDataAdapter myda = new SqlDataAdapter(sqltopadcom, sqlcon);
DataSet ds = myda.Fill(ds);

Name = ds.Tables[0].Rows[0]["name"].ToString();

你要输出数据库里列的信息还是行的信息??
如果是列.
需要先将myda.Fill 到DataSet里.然后取 DataTable.Rows[i];
如果是行.同上.不过需要拼串了.

你这段代码用cmd的感觉能好些

Page.DataBind();
下面写
Response.Write(name);

<%#Na