求教c#,未将对象引用设置到对象的实例问题

问题描述

usingSystem;usingSystem.Collections.Generic;usingSystem.ComponentModel;usingSystem.Data;usingSystem.Drawing;usingSystem.Linq;usingSystem.Text;usingSystem.Windows.Forms;usingSystem.Data.OleDb;namespacestusystem{publicpartialclassAddStuForm:Form{StringName1;StringNumber;StringClas;StringYuanxi;StringMath;StringEnglish;StringWuli;StringSoft;OleDbDataAdapterStudentAdapter;DataTableStudentTable;publicAddStuForm(refDataGridViewdataGridView,refOleDbDataAdapterstudentAdapter,refDataTablestudentTable){InitializeComponent();this.StudentAdapter=studentAdapter;this.StudentTable=studentTable;}publicAddStuForm(){InitializeComponent();}privatevoidbutton2_Click(objectsender,EventArgse){Name1=textBox1.Text;Number=textBox2.Text;Clas=textBox3.Text;Yuanxi=textBox4.Text;Math=textBox5.Text;English=textBox7.Text;Wuli=textBox6.Text;Soft=textBox8.Text;if(true){this.Validate();DataRowrow=StudentTable.NewRow();//未将对象引用设置到对象的实例row["姓名"]=Name1;row["学号"]=Number;row["班级"]=Clas;row["院系"]=Yuanxi;row["微积分"]=Math;row["大学英语"]=English;row["大学物理"]=Wuli;row["软件课设"]=Soft;try{StudentAdapter.Update(StudentTable);}catch(OleDbExceptionerr){MessageBox.Show(err.Message,"添加失败");}}}}}StudentTable指向Null?已经给了值,为何不存在?

解决方案

解决方案二:
StudentTable—>NULLNULL.NewRow()未将对象引用设置到对象的实例
解决方案三:
检查参数。。。studentTable传进来的应该为NULL
解决方案四:
StudentTable给的是引用1本来传递的就是NULL2原始对象引用被设置成NULL
解决方案五:
StudentTable是不是空啊
解决方案六:
StudentTable未实例化吧!
解决方案七:
引用3楼ghost5216的回复:

StudentTable给的是引用1本来传递的就是NULL2原始对象引用被设置成NULL

2原始对象引用被设置成NULL说错了
解决方案八:
引用楼主asver001的回复:

StudentTable指向Null?已经给了值,为何不存在?

你哪里给StudentTable赋值了?
解决方案九:
应该StudentTable未实例化
解决方案十:
哪有这种写法,传参有问题。
解决方案十一:
publicAddStuForm(refDataGridViewdataGridView,refOleDbDataAdapterstudentAdapter,refDataTablestudentTable){InitializeComponent();this.StudentAdapter=studentAdapter;this.StudentTable=studentTable;}

这个构造函数到底调用了没有?
解决方案十二:
在出问题的代码那,给个判断if(){//=====}你再看看有每问题
解决方案十三:
引用10楼buyong的回复:

C#codepublicAddStuForm(refDataGridViewdataGridView,refOleDbDataAdapterstudentAdapter,refDataTablestudentTable){InitializeComponent();this.StudentAdapter=studentAdapter;……

看看你给this.StudentAdapter赋的是不是空值。哈哈。
解决方案十四:
StudentTable未实例化
解决方案十五:
实例化后,如果有实体的某个参数未赋值或为空,也会报这种错。
解决方案:
在StudentTable处打个断点,或直接跟踪参数调试
解决方案:
studenttable打了断点,是NULL,程序被调用但没有操作……数据没有传进来……加MAIN1也没有用,求解?

时间: 2024-09-04 21:25:09

求教c#,未将对象引用设置到对象的实例问题的相关文章

编程-菜鸟求教『未将对象引用设置到对象的实例。』

问题描述 菜鸟求教『未将对象引用设置到对象的实例.』 在这里如何使变量实例化呢? 解决方案 把imgstyle = combobox1.selectindex写在你的函数里,select case上面. 解决方案二: 未将对象引用设置到对象的实例 一.网络上的一般说法 1.ViewState对象为Null. 2.DateSet空. 3.sql语句或Datebase的原因导致DataReader空. 4.声明字符串变量时未赋空值就应用变量. 5.未用new初始化对象. 6.Session对象为空.

asp.net-其他信息: 未将对象引用设置到对象的实例。

问题描述 其他信息: 未将对象引用设置到对象的实例. 想要用代码来编辑gridview控件的数据:然而我运行时告诉我"其他信息: 未将对象引用设置到对象的实例."求教各位大神,该怎么改,最好有代码:下面就是我的代码,不重要的收起来了: using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.W

错误解决:System.NullReferenceException: 未将对象引用设置到对象的实例

在ASP.NET开发中,遇到System.NullReferenceException: 未将对象引用设置到对象的实例的错误提示,解决方法如下:       (1)所设置的变量为空值或没有取到值,一般出现在传递参数的时候出现这个问题,也会在使用datagrid或gridview或datalist等数据控件时出现. (2)控件名称与codebehind里面的没有对应 (3)未用new初始化对象 (4)在程序中所引用的控件不存在 解决方法: (1)使用try..catch...finally捕捉错误

在win7 64位下出现异常:未将对象引用设置到对象的实例

  您好,win7的确有这个问题,已经反馈给作者,其实很多.net写的应用会出现这样的错误,然后无视它的话,能继续用就好了,这个似乎不行. 电脑模拟乐器软件1.20 绿色版"在win7 64位下出现异常:未将对象引用设置到对象的实例.具体情况如下:‍ ************** 异常文本 ************** ************** 已加载的程序集 ************** mscorlib 程序集版本: 2.0.0.0 Win32 版本: 2.0.50727.5477 (W

链接数据库时,对文件操作造成脚本异常:未将对象引用设置到对象的实例,感觉是代码出了问题

问题描述 链接数据库时,对文件操作造成脚本异常:未将对象引用设置到对象的实例,感觉是代码出了问题 第一次对文件进行操作,只是简单的添加照片而已,不知道问题出在那里,当我把操作文件那块代码注释后,其他功能都是正常的,代码如下: string fileExtesion = Path.GetExtension(FileUpload1.PostedFile.FileName).ToLower(); if (FileUpload1.HasFile) { string path = Server.MapPa

图片-使用httpcontext.current.session时出错,未将对象引用设置到对象的实例。

问题描述 使用httpcontext.current.session时出错,未将对象引用设置到对象的实例.

上传服务器后出现System.NullReferenceException: 未将对象引用设置到对象的实例。

问题描述 如题[NullReferenceException:未将对象引用设置到对象的实例.]TopWin.WebUI.game._3jymdd.Page_Load(Objectsender,EventArgse)ine:topwincmswebuigame3jymdd.aspx.cs:80System.Web.UI.Control.OnLoad(EventArgse)+67System.Web.UI.Control.LoadRecursive()+35System.Web.UI.Page.Pr

VC 访问web service 出错!服务无法处理请求 未将对象引用设置到对象的实例

问题描述 ISoapSerializerPtrSerializer;ISoapReaderPtrReader;ISoapConnectorPtrConnector;//ConnecttotheserviceConnector.CreateInstance(__uuidof(HttpConnector));//WS服务器地址Connector->Property["EndPointURL"]="http://www.webxml.com.cn/webservices/qq

未将对象引用设置到对象的实例。哪位能帮帮忙?已经找了几天还没找到问题

问题描述 "/xinwenfabu"应用程序中的服务器错误.--------------------------------------------------------------------------------未将对象引用设置到对象的实例.说明:执行当前Web请求期间,出现未处理的异常.请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息.异常详细信息:System.NullReferenceException:未将对象引用设置到对象的实例.源错误:行77: