try
{
string con = ConfigurationSettings.AppSettings["SqlConnectionString"];
SqlConnection conn = new SqlConnection(con);
conn.Open();
string rq = Request.QueryString["id"];
string sql = "SELECT * FROM news WHERE id = rq";
SqlDataAdapter myCommand = new SqlDataAdapter();
myCommand.SelectCommand = new SqlCommand(sql,conn);
DataSet ds = new DataSet();
myCommand.Fill(ds,"news");
DataList1.DataSource = ds;
DataList1.DataBind();
conn.Close();
}
catch (SqlException ex)
{
Console.WriteLine("Exception in Main:" + ex.Message);
}
{
string con = ConfigurationSettings.AppSettings["SqlConnectionString"];
SqlConnection conn = new SqlConnection(con);
conn.Open();
string rq = Request.QueryString["id"];
string sql = "SELECT * FROM news WHERE id = rq";
SqlDataAdapter myCommand = new SqlDataAdapter();
myCommand.SelectCommand = new SqlCommand(sql,conn);
DataSet ds = new DataSet();
myCommand.Fill(ds,"news");
DataList1.DataSource = ds;
DataList1.DataBind();
conn.Close();
}
catch (SqlException ex)
{
Console.WriteLine("Exception in Main:" + ex.Message);
}
Console.Write()控制台输出:
在webform下可改成:
Console.WriteLine("Exception in Main:" + ex.Message);
===>
Response.Write("Exception in Main:" + ex.Message);
<asp:DataList id="DataList1"
runat="server">
<ItemTemplate>
<div align=center><strong><%=新闻标题%></strong></div><br>
<%=新闻内容%><br>
<div align=right><%=发布单位%><br>
<%=发布时间%><br></div>
</ItemTemplate>
</asp:DataList></FONT>
我这样的代码为什么还不能显示???
如下.道理不说了。你自己看书...
<ItemTemplate>
<asp:Label ID=label1 Runat=server Text='<%# DataBinder.Eval(Container.DataItem,"新闻标题")%>'>
</ItemTemplate>
string sql = "SELECT * FROM news WHERE id = " + rq;
其实应该这样的,上面是我以前写的代码 ,有点错。关于你所说的异常输出能不能具体点呢?我那个输出也是书上的例子,感觉不够实用。