private void Page_Load(object sender, System.EventArgs e)
{
OleDbConnection sqlcon1=new OleDbConnection(ConfigurationSettings.AppSettings.Get("NWindOle"));
OleDbDataAdapter oadp1=new OleDbDataAdapter("select lastname,employeeid from employees",sqlcon1);
DataSet ds1=new DataSet();
oadp1.Fill(ds1,"name");
DataGrid1.DataSource=ds1.Tables["name"];
DataGrid1.DataBind();
sqlcon1.Close();
}
此外没有其它代码了出错句:DataGrid1.DataSource=ds1.Tables["name"];
出错信息:未将对象引用设置到对象的实例。
异常详细信息: System.NullReferenceException: 未将对象引用设置到对象的实例。
{
OleDbConnection sqlcon1=new OleDbConnection(ConfigurationSettings.AppSettings.Get("NWindOle"));
OleDbDataAdapter oadp1=new OleDbDataAdapter("select lastname,employeeid from employees",sqlcon1);
DataSet ds1=new DataSet();
oadp1.Fill(ds1,"name");
DataGrid1.DataSource=ds1.Tables["name"];
DataGrid1.DataBind();
sqlcon1.Close();
}
此外没有其它代码了出错句:DataGrid1.DataSource=ds1.Tables["name"];
出错信息:未将对象引用设置到对象的实例。
异常详细信息: System.NullReferenceException: 未将对象引用设置到对象的实例。
解决方案 »
- vs2008发布网站的时候Release后为什么Bin下.pdb不会自动删除了?
- MVC中弹出对话框
- 咋个报:并非所有的代码路径都返回
- 求 easyui datagrid asp.net 分页案例
- 如何在asp.net中实现在信息提示效果?
- UpdatePanel1 面页上使用了这个,怎么自动提交表单.
- 关于.NET中MVC设计模式?
- 有什么办法使得不能直接访问指定目录下的指定后缀的文件
- 为什么 我不可以用where函数呢?
- (一个民工的困惑)我用一个Button1虚拟激发file控件的浏览按钮,用一个web button2提交的时候,为什么要点击两次它才提交?
- datalist的选择问题
- 莫名其妙的错误??????
新加一句,打印sql语句,把打印出来的到查询分析器里执行一下,看看能否执行
在vs2005里,我将datagrid换成datagridview后自己写了连接字符串,测试没问题。
当然,没有DataGrid1.DataBind();类似的句子,因为datagridview没有DataBind()方法。因为,我觉得是不是楼主的配置文件有问题呢?
是不是用小括号啊
是不是用小括号啊
~~~~~~~~~~~~~~~~
就应该是中括号,不是这个的问题
DataGrid1.DataSource=ds1;
{
OleDbConnection sqlcon1=new OleDbConnection(ConfigurationSettings.AppSettings.Get("NWindOle"));
OleDbDataAdapter oadp1=new OleDbDataAdapter("select lastname,employeeid from employees",sqlcon1);
DataSet ds1=new DataSet();
oadp1.Fill(ds1,"name");if(ds1.Tables.Contain("name"))
DataGrid1.DataSource=ds1.Tables["name"];
else
{
Response.Write("请检查连接字符串和sql语句");
}
DataGrid1.DataBind();
sqlcon1.Close();
}