还有在调用“Fill”前,SelectCommand 属性尚未初始化。怎么改
下面那是我写的代码
y
{
string strCon = @" Provider = Microsoft.Jet.OLEDB.4.0 ; Data Source = .\\tongxunlu.mdb " ;
OleDbConnection myConn = new OleDbConnection ( strCon ) ;
myConn.Open ( ) ;
string strDele = "DELETE FROM myfriend WHERE xingming= '" + txtName.Text+"'" ;
OleDbCommand myCommand = new OleDbCommand ( strDele , myConn ) ;
//从数据库中删除指定记录
myCommand.ExecuteNonQuery ( ) ;
//从DataSet中删除指定记录信息
OleDbDataAdapter dt=new OleDbDataAdapter();
DataSet myDataSet =new DataSet();
dt.Fill(myDataSet,"myfriend");
myDataSet.Tables["myfriend"].Rows [ myBind.Position ].Delete ( ) ;
myDataSet.Tables["myfriend"].AcceptChanges ( ) ;
MessageBox.Show("删除成功");
myConn.Close ( ) ;
}
catch(OleDbException ex)
{
MessageBox.Show(ex.ToString());
}
catch(NullReferenceException exx)
{
MessageBox.Show(exx.ToString());
}
}