主题:一个关于数据操作的问题
我在写一个程序,其中有涉及到对数据的修改,可是怎么也不能修改,系统老报告错误:"未将对象引用设置到对象实列"
这是代码
try
{
int a=this.dataGrid1.CurrentCell.RowNumber;
string strCon="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=d:\\book.mdb";
OleDbConnection myConn=new OleDbConnection(strCon);
myConn.Open();
string strCom1="UPDATE book set CSharp='"+this.myDataSet.Tables["book"].Rows[a][2]+"',数学='"+this.myDataSet.Tables["book"].Rows[a][3]+"',英语="+this.myDataSet.Tables["book"].Rows[a][4]+",WINDOWS2K="+this.myDataSet.Tables["book"].Rows[a][5]+" ,共选课='"+this.myDataSet.Tables["book"].Rows[a][6]+",电路分析='"+this.myDataSet.Tables["book"].Rows[a][7]+",PHOTOSHOP='"+this.myDataSet.Tables["book"].Rows[a][8]+",平均分='"+this.myDataSet.Tables["book"].Rows[a][9]+"where 学号="+this.myDataSet.Tables["book"].Rows[a][1];
OleDbCommand inst=new OleDbCommand(strCom1,myConn);
System.Windows.Forms.MessageBox.Show(strCom1);
inst.ExecuteNonQuery();
OleDbDataAdapter myCommand2=new OleDbDataAdapter("SELECT * FROM sj1 order by 学号",myConn);
this.myDataSet.Clear();
myCommand2.Fill(myDataSet,"sj1");
myConn.Close();
}
catch(Exception x)
{MessageBox.Show("错误"+x.ToString(),"error");}
这是代码
try
{
int a=this.dataGrid1.CurrentCell.RowNumber;
string strCon="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=d:\\book.mdb";
OleDbConnection myConn=new OleDbConnection(strCon);
myConn.Open();
string strCom1="UPDATE book set CSharp='"+this.myDataSet.Tables["book"].Rows[a][2]+"',数学='"+this.myDataSet.Tables["book"].Rows[a][3]+"',英语="+this.myDataSet.Tables["book"].Rows[a][4]+",WINDOWS2K="+this.myDataSet.Tables["book"].Rows[a][5]+" ,共选课='"+this.myDataSet.Tables["book"].Rows[a][6]+",电路分析='"+this.myDataSet.Tables["book"].Rows[a][7]+",PHOTOSHOP='"+this.myDataSet.Tables["book"].Rows[a][8]+",平均分='"+this.myDataSet.Tables["book"].Rows[a][9]+"where 学号="+this.myDataSet.Tables["book"].Rows[a][1];
OleDbCommand inst=new OleDbCommand(strCom1,myConn);
System.Windows.Forms.MessageBox.Show(strCom1);
inst.ExecuteNonQuery();
OleDbDataAdapter myCommand2=new OleDbDataAdapter("SELECT * FROM sj1 order by 学号",myConn);
this.myDataSet.Clear();
myCommand2.Fill(myDataSet,"sj1");
myConn.Close();
}
catch(Exception x)
{MessageBox.Show("错误"+x.ToString(),"error");}