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

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()

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值