问题描述
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也没有用,求解?