在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()
好像是数据库不能打开似的。怎么解决呢?
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
- 在Pocket Pc 2003的Form1中放一个DataGrid控件,通过下面的方法连接到数据表,为什么不显示表中的数据呢?
- 在form2中调用form1中的方法并改变form1中控件值的另一种方法
- datagrid放在隐藏层不显示数据的问题
- Pocket PC 中 DataGrid 的用法
- 求助,这样的文本文件如何读取出来并放在一个DataGrid控件中显示?
- 在Pocket PC应用程序中使用DataGrid控件
- 在Pocket PC应用程序中使用DataGrid控件
- 在Pocket PC应用程序中使用DataGrid控件
- 通过ActiveSync将Windows Mobile(Pocket PC)虚拟机连接到PC的两个注意事项
- 一个表单中的数据添加到不同的数据表中
- 在datagrid控件中显示多列的方法
- [VB.NET]怎样在DataGrid控件中显示不同数量的不同图片呢?
- 为什么使用ADO Data控件的Delete方法无法删除DataGrid控件中的数据
- PopWindows放在某个控件的下面
- Flex中DataGrid通过存储在List中的JAVABEAN提供数据时候,数据不能正常显示的问题
- java连接Postger数据库,并通过Jsp将数据库中数据表的在网页中显示
- 单击DataGrid的行,使这行的数据显示在这个页面的下面,有点像winform的一个列表
- 单击DataGrid的行,使这行的数据显示在这个页面的下面,有点像winform的一个列表
- Android Bound Services 简单使用
- 第十五期 在AOSP上建立一个新产品《手机就是开发板》
- 使用Android-PullToRefresh报错
- 如何显示当月的所有日期
- 有没有类似淘宝app的例子
- 在Pocket Pc 2003的Form1中放一个DataGrid控件,通过下面的方法连接到数据表,为什么不显示表中的数据呢?
- 一个表单提交纠错引起的问题,session在上级页面继承
- Python 将一个正整数分解质因数
- 求助,动态网页的缓存问题
- 2017年1月2日
- 使用化境无组件上传文件,提示错误
- 日期的操作
- j2me和asp交互,j2me端如何正确显示asp返回的汉字
- 这个asp中 insert into 语句那里错误了