如题:
修改Access数据库表
public int ExecuteSQL(string strSQL)
{
int RowsAffected = 0; //被更新的行数
this.Open();
this.oCommand = new OleDbCommand(strSQL,this.oConnection);
RowsAffected = this.oCommand.ExecuteNonQuery();
return RowsAffected;
}
获取access数据库表
public DataSet GetDataSet(string strSQL,string TableName)
{
try
{
this.Open();
this.oAdapter = new OleDbDataAdapter(strSQL,this.oConnection);
this.oDataSet = new DataSet();
this.oAdapter.Fill(this.oDataSet,TableName);
return this.oDataSet;
}
catch(Exception ex)
{
ex.ToString();
return null;
}
}
前台:
Data.DataBase oDB = new WebTest.Data.DataBase() ;
oDB.ExecuteSQL( "UPDATE [City] SET Num = Num+5 WHERE id = 1 ");
DataSet oDS = oDB.GetDataSet( "Select * from [City] " , "t" ) ;
DataGrid1.DataSource = oDS.Tables["t"] ;
DataGrid1.DataBind();
修改Access数据库表
public int ExecuteSQL(string strSQL)
{
int RowsAffected = 0; //被更新的行数
this.Open();
this.oCommand = new OleDbCommand(strSQL,this.oConnection);
RowsAffected = this.oCommand.ExecuteNonQuery();
return RowsAffected;
}
获取access数据库表
public DataSet GetDataSet(string strSQL,string TableName)
{
try
{
this.Open();
this.oAdapter = new OleDbDataAdapter(strSQL,this.oConnection);
this.oDataSet = new DataSet();
this.oAdapter.Fill(this.oDataSet,TableName);
return this.oDataSet;
}
catch(Exception ex)
{
ex.ToString();
return null;
}
}
前台:
Data.DataBase oDB = new WebTest.Data.DataBase() ;
oDB.ExecuteSQL( "UPDATE [City] SET Num = Num+5 WHERE id = 1 ");
DataSet oDS = oDB.GetDataSet( "Select * from [City] " , "t" ) ;
DataGrid1.DataSource = oDS.Tables["t"] ;
DataGrid1.DataBind();
{
int pay2=int.Parse(this.textBox4.Text);
int income2=int.Parse(this.textBox5.Text);
string StrSQL="UPDATE 个人用户表 SET year='"+this.textBox1.Text+"'AND Month='"+this.textBox2.Text+"'AND Day='"+this.textBox3.Text+"'AND Pay="+pay2+"AND Income="+income2+"AND Rea='"+this.textBox6.Text+"'"+ "WHERE Year='"+this.textBox1.Text+"'AND Month='"+this.textBox2.Text+"'AND Day='"+this.textBox3.Text+"'AND Pay="+pay2+"AND Income="+income2+"AND Rea='"+this.textBox6.Text+"'";
this.oleDbCommand1.CommandText=StrSQL;
this.oleDbCommand1.Connection=this.oleDbConnection1;
this.oleDbConnection1.Open();
this.oleDbCommand1.ExecuteNonQuery();
this.oleDbConnection1.Close();
this.dataSet1.Tables["个人用户表"].Rows[this.MyBind.Position].BeginEdit();
this.dataSet1.Tables["个人用户表"].Rows[this.MyBind.Position].EndEdit();
this.dataSet1.AcceptChanges();
this.oleDbDataAdapter1.Fill(this.dataSet1,"个人用户表");
this.MyBind.Position=0;
this.dataSet1.Clear();//大概就是这句
this.oleDbDataAdapter1.Fill(this.dataSet1);//和这句
MessageBox.Show("删除成功!","信息提示",MessageBoxButtons.OK,MessageBoxIcon.Information);
}
this.oleDbDataAdapter1.Fill(this.dataSet1);//和这句
不就等于把DataSet清空了,哪里还有数据等待解决,就结贴~~~
Data.DataBase oDB = new WebTest.Data.DataBase() ;
oDB.ExecuteSQL( "UPDATE [City] SET Num = Num+5 WHERE id = 1 ");
关闭连接
打开连接
DataSet oDS = oDB.GetDataSet( "Select * from [City] " , "t" ) ;
DataGrid1.DataSource = oDS.Tables["t"] ;
DataGrid1.DataBind();即可。
数据库里的数据改掉了~~to:y1g1y1
早试过了
更新完就
关闭连接
打开连接
再提取数据
一样是不行 不信的话你建个简单的access试试