C# 向数据库中添加 修改数据库的两种方法Sql语句和update(dataSet)

时间:2022-03-12 07:26:00

1 ,直接使用Sql语句

string strCom = "delete from account where uid ='" + this.TextBoxUid.Text + "'";
     thisCommand = new OleDbCommand(strCom,thisConnection);
     thisCommand.ExecuteNonQuery();

2,使用OleDbDataAdapter.Update(DataSet) 添加数据

...

DataRow thisRow = thisDataSet.Tables["account"].NewRow();
      thisRow["uid"] = this.TextBoxUid.Text;
      thisRow["pwd"] = this.TextBoxPwd.Text;
    ...

      thisDataSet.Tables["account"].Rows.Add(thisRow);
      OleDbCommandBuilder thisBuilder = new OleDbCommandBuilder(thisAdapter);
      thisBuilder.QuotePrefix = "[";
      thisBuilder.QuoteSuffix = "]";
      thisAdapter.Update(thisDataSet,"account");

3,使用OleDbDataAdapter.Update(DataSet) 更新数据

thisAdapter.Fill(thisDataSet); 
    thisDataSet.Tables[0].Rows[0]["pwd"] = this.TextBoxPwd.Text;
    thisDataSet.Tables[0].Rows[0]["x1"] = this.TextBoxX1.Text;
...

    thisAdapter.Update(thisDataSet);

生活总是如此艰辛,不光现在而已.