在Pocket Pc 2003的Form1中放一个DataGrid控件,通过下面的方法连接到数据表,为什么不显示表中的数据呢?

来源:互联网 发布:淘宝使用他人图片 编辑:程序博客网 时间:2024/05/14 04:15
protected string connStr = "Data Source=.;Initial Catalog=NewDB;Integrated Security=True";
private void Form1_Load(object sender, EventArgs e)
{
    string SelectSql = "Select * from news";
    SqlConnection cn = new SqlConnection(connStr);
    SqlDataAdapter da = new SqlDataAdapter(SelectSql, cn);
    DataSet ds = new DataSet();
    cn.Open(); ---------→①
    da.Fill(ds);
    dataGrid1.DataSource = ds;
    //dataGrid1.DataBindings();
    cn.Close();
}

执行到①句时就报错。具体信息是:

未处理 System.Data.SqlClient.SqlException
  Message="SqlException"
  Class=20
  LineNumber=0
  Number=17
  Procedure="ConnectionOpen (Connect())."
  Server="."
  Source=".Net SqlClient Data Provider"
  State=0
  StackTrace:
    位于 System.Data.SqlClient.SqlConnection.OnError()
    位于 System.Data.SqlClient.SqlInternalConnection.OnError()
    位于 System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning()
    位于 System.Data.SqlClient.TdsParser.Connect()
    位于 System.Data.SqlClient.SqlInternalConnection.OpenAndLogin()
    位于 System.Data.SqlClient.SqlInternalConnection..ctor()
    位于 System.Data.SqlClient.SqlConnection.Open()
    位于 ShowDB.Form1.Form1_Load()
    位于 System.Windows.Forms.Form.OnLoad()
    位于 System.Windows.Forms.Form._SetVisibleNotify()
    位于 System.Windows.Forms.Control.set_Visible()
    位于 System.Windows.Forms.Application.Run()
    位于 ShowDB.Program.Main()

好像是数据库不能打开似的。怎么解决呢?

0 0
原创粉丝点击