|
问个问题?!
1.aspx和2.aspx有何不同?
1.aspx:
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SqlClient" %>
<%@ Page Language="C#" Debug="true" %>
<html>
<script language="C#" runat="server">
void Page_Load(Object sender, EventArgs e)
{
SqlConnection myConnection = new SqlConnection("server=WEIPENG;database=pubs;uid =sa;pwd=123;" ;
SqlDataAdapter sda = new SqlDataAdapter("SELECT * FROM" +
" Titles", myConnection);
DataSet ds = new DataSet();
sda.Fill(ds);
MyRepeater.DataSource = ds;
MyRepeater.DataBind();
}
</script>
<body topmargin="0" leftmargin="0" marginwidth="0" marginheight="0">
<ASP:Repeater id="MyRepeater" runat="server">
<HeaderTemplate>
<Table width="100%" style="font: 8pt verdana">
<tr style="background-color : DFA894">
<th>
Title
</th>
<th>
Title ID
</th>
<th>
Type
</th>
<th>
Publisher ID
</th>
<th>
Price
</th>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr style="background-color:FFECD8">
<td>
<%# DataBinder.Eval(Container.DataItem, "title" %>
</td>
<td>
<%# DataBinder.Eval(Container.DataItem,"title_id" %>
</td>
<td>
<%# DataBinder.Eval(Container.DataItem, "type" %>
</td>
<td>
<%# DataBinder.Eval(Container.DataItem, "pub_id" %>
</td>
<td>
<%# DataBinder.Eval(Container.DataItem,
"price", "{0:c}" %>
</td>
</tr>
</ItemTemplate>
<FooterTemplate>
</Table>
</FooterTemplate>
</ASP:Repeater>
</body>
</html>
2.aspx
<% Import Namespace="System.Data" %>
<% Import Namespace="System.Data.SqlClient" %>
<% Page Language = "C#" Debug = "true" %>
<html>
<script language = "C#" runat = "server">
void Page_Load (Object sender, EventArgs e)
{
SqlConnection myConnection = new SqlConnection ("server=WEIPENG;database=pubs;uid=sa;pwd=123;" ;
SqlDataAdapter sda = new SqlDataAdapter("SELECT * FROM " + "Titles", myConnection);
DataSet ds = new DataSet();
sda.Fill(ds);
MyRepeater.DataSource = ds;
MyRepeater.DataBind();
}
</script>
<body topmargin = "0" leftmargin = "0" marginwidth="0" marginheight="0">
<ASP:Repeater id ="MyRepeater" runat ="server">
<HeaderTemplate>
<Table width ="100%" style ="font:8pt verdana">
<tr style = "background-color : DFA894">
<th>Title</th>
<th>Title ID </th>
<th>Type</th>
<th>Publisher ID </th>
<th>Price </th>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr style ="background-color:FFECD8">
<td><%# DataBinder.Eval(Container.DataItem, "title" %>
</td>
<td><%# DataBinder.Eval(Container.DataItem, "title_id" %>
</td>
<td><%# DataBinder.Eval(Container.DataItem, "type" %>
</td>
<td><%# DataBinder.Eval(Container.DataItem, "pub_id") %>
</td>
<td><%# DataBinder.Eval(Container.DataItem, "price", "{0:c}") %>
</td>
</tr>
</ItemTemplate>
<FooterTemplate>
</Table>
</FooterTemplate>
</ASP:Repeater>
</body>
</html>
1.aspx能正常运行读到数据 2.aspx报错:编译器错误信息: CS0246: 找不到类型或命名空间名称“SqlConnection”(是否缺少 using 指令或程序集引用?)
行 8: SqlConnection myConnection = new SqlConnection ("server=WEIPENG;database=pubs;uid=sa;pwd=123;"); |
|