首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

小白跪求解决方案啊 《在连接环境中使用ADO.NET》课本上的小例子解决思路

2012-04-10 
小白跪求解决方案啊《在连接环境中使用ADO.NET》课本上的小例子.aspx.cs文件的内容:using Systemusing Syst

小白跪求解决方案啊 《在连接环境中使用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();
先把这句去掉

热点排行