急!C#操作Access update语句
C#操作Accessupdate语句执行不报错也返回了影响行数但打开Access就是没更新数据以下是代码:if(newDbHelp().ExecuteUpdate("Up...
C#操作Access update语句执行不报错 也返回了影响行数 但打开Access就是没更新数据 以下是代码:
if (new DbHelp().ExecuteUpdate("Update Fees Set feeTitleId = " + this.cbFeeTitle.SelectedValue.ToString() + " , fee = " + this.tbFee.Text.Trim() + " , feeDetail = '" + this.tbFeeDetail.Text + "' Where feeId=" + this.feeId) == 1)
{
MessageBox.Show("保存成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
else
{
MessageBox.Show("保存失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
DbHelp:
public int ExecuteUpdate(string cmdText)
{
int rows = -1;
this.command = new OleDbCommand();
command.Connection = con;
command.CommandType = CommandType.Text;
command.CommandText = cmdText;
try
{
this.con.Open();
rows=this.command.ExecuteNonQuery();
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
finally
{
if (this.con.State != ConnectionState.Closed)
{
this.con.Close();
}
}
return rows;
} 展开
if (new DbHelp().ExecuteUpdate("Update Fees Set feeTitleId = " + this.cbFeeTitle.SelectedValue.ToString() + " , fee = " + this.tbFee.Text.Trim() + " , feeDetail = '" + this.tbFeeDetail.Text + "' Where feeId=" + this.feeId) == 1)
{
MessageBox.Show("保存成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
else
{
MessageBox.Show("保存失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
DbHelp:
public int ExecuteUpdate(string cmdText)
{
int rows = -1;
this.command = new OleDbCommand();
command.Connection = con;
command.CommandType = CommandType.Text;
command.CommandText = cmdText;
try
{
this.con.Open();
rows=this.command.ExecuteNonQuery();
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
finally
{
if (this.con.State != ConnectionState.Closed)
{
this.con.Close();
}
}
return rows;
} 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询