我想在设置完指定值后,实现数据库指定表的更新,如何来实现呢? //设置数据库中指定表中指定行列值
public void SetSpecificValue(string strTableName, int iRows, string strFeildName, string strValue)
{
//创建并打开OLEDB链接
OleDbConnection objConnection = new OleDbConnection(attConnectionString);
objConnection.Open();
//初始化SQL字符串
string strSQL = "SELECT * FROM " + strTableName;
//创建数据适配器
OleDbDataAdapter daAPIStruct = new OleDbDataAdapter(strSQL, objConnection);
//创建表
DataTable dtAPIStruct = new DataTable();
//填充表
daAPIStruct.Fill(dtAPIStruct); //直接OleDbDataAdapter.Fill(dtAPIStruct);
//返回值
dtAPIStruct.Rows[iRows][strFeildName]=strValue;
//daAPIStruct.Update(;
//关闭链接
objConnection.Close();
}
public void SetSpecificValue(string strTableName, int iRows, string strFeildName, string strValue)
{
//创建并打开OLEDB链接
OleDbConnection objConnection = new OleDbConnection(attConnectionString);
objConnection.Open();
//初始化SQL字符串
string strSQL = "SELECT * FROM " + strTableName;
//创建数据适配器
OleDbDataAdapter daAPIStruct = new OleDbDataAdapter(strSQL, objConnection);
//创建表
DataTable dtAPIStruct = new DataTable();
//填充表
daAPIStruct.Fill(dtAPIStruct); //直接OleDbDataAdapter.Fill(dtAPIStruct);
//返回值
dtAPIStruct.Rows[iRows][strFeildName]=strValue;
//daAPIStruct.Update(;
//关闭链接
objConnection.Close();
}
private SqlDataAdapter SDA = new SqlDataAdapter();
try
{
SqlCommandBuilder SCB = new SqlCommandBuilder(SDA);
SDA.Update(DT);
}
catch (System.Exception ex)
{
MessageBox.Show(ex.ToString());
return;
}
MessageBox.Show("更新成功!");
//设置数据库中指定表中指定行列值
public void SetSpecificValue(string strTableName, int iRows, string strFeildName, string strValue, string strLocate)
{
//创建并打开OLEDB链接
OleDbConnection objConnection = new OleDbConnection(attConnectionString);
objConnection.Open();
//初始化SQL字符串
string strSQL = "SELECT * FROM " + strTableName;
//创建数据适配器
OleDbDataAdapter daAPIStruct = new OleDbDataAdapter(strSQL, objConnection); //创建表
DataTable dtAPIStruct = new DataTable();
dtAPIStruct.TableName = strTableName; //填充表
daAPIStruct.Fill(dtAPIStruct); //直接OleDbDataAdapter.Fill(dtAPIStruct);
//返回值
dtAPIStruct.Rows[iRows][strFeildName]=strValue; DataSet dsAPIStruct = new DataSet("dsAPIStruct");
dsAPIStruct.Tables.Add(dtAPIStruct); string strUpdateCommand = "UPDATE " + strTableName + " SET " + strFeildName + "='" + strValue + "'" + " WHERE Name='" + strLocate+"'"; daAPIStruct.UpdateCommand = new OleDbCommand();
daAPIStruct.UpdateCommand.CommandText = strUpdateCommand;//抛出异常 未将对象引用设置到对象的实例。
daAPIStruct.UpdateCommand.Connection = objConnection;
daAPIStruct.Update(dsAPIStruct, strTableName);
//关闭链接
objConnection.Close();
}