读书人

小白跪求解决方案啊 《在连接环境中使

发布时间: 2012-04-10 21:03:56 作者: rapoo

小白跪求解决方案啊 《在连接环境中使用ADO.NET》课本上的小例子
.aspx.cs文件的内容:
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;

public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

Label1.Text = "master数据库中emp表中的第一列的数据";
SqlConnection con = new SqlConnection("Initial Catalog=master;Data Source=.;UID=sa;Password='123';");
SqlCommand com = new SqlCommand("select eno from emp", con);
con.Open();
SqlDataReader reader = com.ExecuteReader();
while (reader.Read())
{
ListBox1.Items.Add(reader[0].ToString());
}
con.Close();


}

protected void ListBox1_SelectedIndexChanged(object sender, EventArgs e)
{

}
}
错误提示是:对象名emp 无效。

[解决办法]
master数据库中有emp表吗
[解决办法]
学习的时候,每行代码加上注释
[解决办法]
master数据库中有emp表吗?
还有阅读器使用完后,关闭。
[解决办法]
con.Close();
先把这句去掉

读书人网 >C#

热点推荐