<%@ Page language="c#" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SqlClient" %>
<HTML>
<HEAD>
<script language="C#" runat="server">
private void Page_Load(object sender, System.EventArgs e)
{
SqlConnection myConnection = new SqlConnection();
myConnection.ConnectionString =
"server=(local);uid=sa;pwd=;database=lwzz;Connect Timeout=30";
myConnection.Open();
string sqlString = "select * from student";
SqlCommand myCommand = new SqlCommand(sqlString,myConnection);
SqlDataReader myReader =myCommand.ExecuteReader();
ShowData(myReader);
myReader.Close();
myConnection.Close();
}
public void ShowData(SqlDataReader rd)
{
SqlDataReader myReader=rd;
TableRow tr1= new TableRow();
for(int i=0;i<myReader.FieldCount;i++)
{
TableCell tc = new TableCell();
tc.Text=myReader.GetName(i);
tr1.Cells.Add(tc);
}
tb.Rows.Add(tr1);
while(rd.Read())
{
TableRow tr= new TableRow();
for(int i=0;i<myReader.FieldCount;i++)
{
TableCell tc = new TableCell();
tc.Text=myReader.GetValue(i).ToString();
tr1.Cells.Add(tc);
}
tb.Rows.Add(tr);
}
}
</script>
</HEAD>
<body bgcolor="skyblue">
<form id="Form1" runat="server">
<asp:Table id="tb" runat="server" GridLines="Both" BackColor="SkyBlue"></asp:Table>
</form>
</body>
</HTML>
我在执行时,系统提示"找不到类型或命名空间名称"SqlDataReader".....",为什么啊,我是新手,望高手指正!谢谢
[此贴子已经被作者于2006-8-31 21:15:30编辑过]