asp.net中的网格视图连接问题 [英] grid view connection problem in asp.net

查看:83
本文介绍了asp.net中的网格视图连接问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所有人都快乐,


在我的项目中,我试图将数据库连接提供给网格视图,该视图显示以下error: "Object reference is not set to an instance of an object"请帮助我.


谢谢

Hai to All,


In my project i am trying to give data base connection to the grid view it shows the following error: "Object reference is not set to an instance of an object" please healp me .


thank you

推荐答案

出现问题的原因是您使用的对象没有制作新对象(即带有新关键字)

试试看或将其与您的代码进行比较

The problem is arising as you are using an object with out making new object(ie with new key word)

Try This or compare it with your code

SqlConnection con=new SqlConnection(//connectionstring);
con.Open();
SqlCommand cmd=new SqlCommand();
DataSet ds=new DataSet();
cmd.CommandText="select * from table";
cmd.Connection=con;
SqlDataAdapter ad=new SqlDataAdapter();
ad.Fill(ds);

Gridview.DataSource=ds.Tables[0];
GridView.Databind();


由于Null引用而发生此错误.只需调试代码,在处理对象时代码中可能会有一些错误.
当您尝试引用某些为Null/Nothing的对象时,通常会发生这种情况.
请检查您的连接是否正确初始化,或者您的数据读取器/数据集是否正在从数据库中获取任何值.
只要正确地调试代码,解决方案就在其中:)
This error occurs beacuse Null Reference. Just debug your code , possibly there is some fault in your code while handling objects.
It generally happens when you try to refernce some object which is Null/Nothing.
Please check whether your connection is properly initialzed or your datareader/dataset is fetching any value from database or not.
Just debug the code properly and the solution is there within it only :)


这篇关于asp.net中的网格视图连接问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆