OleDbCommandBuilder更新Access数据库中遇到的问题
部分代码如下:
//AccountQuery.aspx.cs
protected void FormView1_ItemUpdating(object sender,FormViewUpdateEventArgs e)
{
DataQueryBLL dqb = new DataQueryBLL();
try
{
if (dtUpdateData != null && dtUpdateData.Rows.Count > 0)
{
dtUpdateData.Rows[0]["ID"] = ((TextBox)FormView1.Row.FindControl("txtId")).Text;
dtUpdateData.Rows[0]["EMPLOYEE_CODE"] = ((TextBox)FormView1.Row.FindControl("txtECode")).Text;
dtUpdateData.Rows[0]["EMPLOYEE_STATUS"] = ((DropDownList)FormView1.Row.FindControl("drEStatus")).SelectedValue;
dtUpdateData.Rows[0]["EMPLOYEE_NAME"] = ((TextBox)FormView1.Row.FindControl("txtName")).Text;
dtUpdateData.Rows[0]["GENDER"] = ((DropDownList)FormView1.Row.FindControl("drGender")).SelectedValue;
dtUpdateData.Rows[0]["AGE"] = ((TextBox)FormView1.Row.FindControl("txtAge")).Text;
dtUpdateData.Rows[0]["TEAM"] = ((DropDownList)FormView1.Row.FindControl("drTeam")).SelectedValue;
dtUpdateData.Rows[0]["LOCUS"] = ((DropDownList)FormView1.Row.FindControl("drLocus")).SelectedValue;
dtUpdateData.Rows[0]["JP_GRADE"] = ((DropDownList)FormView1.Row.FindControl("drJPGrade")).SelectedValue;
dtUpdateData.Rows[0]["EMPLOYEE_LEVEL"] = ((DropDownList)FormView1.Row.FindControl("drLevel")).SelectedValue;
dtUpdateData.Rows[0]["FEE_RATE"] = ((DropDownList)FormView1.Row.FindControl("drFEERate")).SelectedValue;
dtUpdateData.Rows[0]["SALARY"] = ((TextBox)FormView1.Row.FindControl("txtSalary")).Text;
dtUpdateData.Rows[0]["PROJECT_CODE"] = ((TextBox)FormView1.Row.FindControl("txtPCode")).Text;
dtUpdateData.Rows[0]["PROJECT_TYPE"] = ((DropDownList)FormView1.Row.FindControl("drPType")).SelectedValue;
dtUpdateData.Rows[0]["PROJECT_NAME"] = ((TextBox)FormView1.Row.FindControl("txtPName")).Text;
dtUpdateData.Rows[0]["MOVE_RATE"] = ((TextBox)FormView1.Row.FindControl("txtMRate")).Text;
dtUpdateData.Rows[0]["RMB_PRICE"] = ((TextBox)FormView1.Row.FindControl("txtRPrice")).Text;
dtUpdateData.Rows[0]["JAP_PRICE"] = ((TextBox)FormView1.Row.FindControl("txtJPrice")).Text;
dtUpdateData.Rows[0]["INCOME"] = ((TextBox)FormView1.Row.FindControl("txtIncome")).Text;
dtUpdateData.Rows[0]["RATE"] = ((TextBox)FormView1.Row.FindControl("txtRate")).Text;
dtUpdateData.Rows[0]["RATECOST"] = ((TextBox)FormView1.Row.FindControl("txtRateCost")).Text;
dtUpdateData.Rows[0]["FACTCOST_RMB"] = ((TextBox)FormView1.Row.FindControl("txtFactCostRMB")).Text;
dtUpdateData.Rows[0]["FACTCOST_JAP"] = ((TextBox)FormView1.Row.FindControl("txtFactCostJPY")).Text;
dtUpdateData.Rows[0]["GROSS_PROFIT"] = ((TextBox)FormView1.Row.FindControl("txtGrossProfit")).Text;
}
dqb.UpDateNew(dtUpdateData);
}
catch (Exception ex)
{
throw ex;
}
//DataQueryBLL
//定义数据库连接
public static OleDbConnection conn = new OleDbConnection(AccessDAL.CONN_STRING_DEFAULT);
//定义数据读取器
public static OleDbDataAdapter oldAdp = null;
public void UpDateNew(DataTable dtUpDateTable)
{
oldAdp = new OleDbDataAdapter(" SELECT * FROM EMPLOYEE_ITEM", conn);
OleDbCommandBuilder oledbCB = new OleDbCommandBuilder(oldAdp);
oldAdp.Update(dtUpDateTable);
}
第一个ID字段只是一个顺序,并不是主键,可是当我把ID的索引设置为有重复,就会出现如下错误:
"于不返回任何基表信息的 SelectCommand 不支持动态SQL生成!
他改成没有重复,一切正常,为什么不是主键的ID 的索引,对程序有影响!
有人能为我答复么~谢谢!找了很多相关资料,都没有找出原因!