using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;
namespace stusystem
{
public partial class AddStuForm : Form
{
String Name1;
String Number;
String Clas;
String Yuanxi;
String Math;
String English;
String Wuli;
String Soft;
OleDbDataAdapter StudentAdapter;
DataTable StudentTable; public AddStuForm(ref DataGridView dataGridView , ref OleDbDataAdapter studentAdapter , ref DataTable studentTable)
{
InitializeComponent();
this.StudentAdapter = studentAdapter;
this.StudentTable = studentTable;
}
public AddStuForm()
{
InitializeComponent();
} private void button2_Click(object sender, EventArgs e)
{
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();
DataRow row = StudentTable.NewRow(); //未将对象引用设置到对象的实例
row["姓名"] = Name1;
row["学号"] = Number;
row["班级"] = Clas;
row["院系"] = Yuanxi;
row["微积分"] = Math;
row["大学英语"] = English;
row["大学物理"] = Wuli;
row["软件课设"] = Soft;
try
{
StudentAdapter.Update(StudentTable);
}
catch(OleDbException err)
{
MessageBox.Show(err.Message , "添加失败");
}
}
}
}
}
StudentTable指向Null?已经给了值,为何不存在?
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;
namespace stusystem
{
public partial class AddStuForm : Form
{
String Name1;
String Number;
String Clas;
String Yuanxi;
String Math;
String English;
String Wuli;
String Soft;
OleDbDataAdapter StudentAdapter;
DataTable StudentTable; public AddStuForm(ref DataGridView dataGridView , ref OleDbDataAdapter studentAdapter , ref DataTable studentTable)
{
InitializeComponent();
this.StudentAdapter = studentAdapter;
this.StudentTable = studentTable;
}
public AddStuForm()
{
InitializeComponent();
} private void button2_Click(object sender, EventArgs e)
{
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();
DataRow row = StudentTable.NewRow(); //未将对象引用设置到对象的实例
row["姓名"] = Name1;
row["学号"] = Number;
row["班级"] = Clas;
row["院系"] = Yuanxi;
row["微积分"] = Math;
row["大学英语"] = English;
row["大学物理"] = Wuli;
row["软件课设"] = Soft;
try
{
StudentAdapter.Update(StudentTable);
}
catch(OleDbException err)
{
MessageBox.Show(err.Message , "添加失败");
}
}
}
}
}
StudentTable指向Null?已经给了值,为何不存在?
1 本来传递的就是NULL
2 原始对象引用被设置成NULL
说错了
{
InitializeComponent();
this.StudentAdapter = studentAdapter;
this.StudentTable = studentTable;
}
这个构造函数到底调用了没有?
看看你给 this.StudentAdapter 赋的是不是空值。哈哈。