OleDbCommandBuilder无法更新
string strSql = "SELECT * FROM USE";
string src = Request.PhysicalApplicationPath+"Aod.mdb";
string strConnection = "Provider=Microsoft.Jet.OleDb.4.0;";
strConnection += @"Data Source=" + src;
OleDbConnection objconnection = new OleDbConnection(strConnection);
OleDbDataAdapter objAdapter = new OleDbDataAdapter(strSql, objconnection);
DataSet objDatasSet = new DataSet();
try
{
objAdapter.Fill(objDatasSet, "USE");
DataView objDataView = new DataView(objDatasSet.Tables["USE"]);
dgList.DataSource = objDataView;
dgList.DataBind();
}
catch(OleDbException objError)
{
if (objError.Message.Substring(0, 21) == "Login failed for user")
{
Response.Write("登陆失败");
}
else if (objError.Message.Substring(0, 19) == "Could not find file")
{
Response.Write("找不到指定数据库");
}
else
{
Response.Write("<br/>message-"+objError.Message);
Response.Write("<br/>source-" + objError.Source);
}
}
OleDbCommandBuilder objBuilder = null;
objBuilder = new OleDbCommandBuilder(objAdapter);
objAdapter.UpdateCommand = objBuilder.GetUpdateCommand();
objAdapter.DeleteCommand = objBuilder.GetDeleteCommand();
objAdapter.InsertCommand = objBuilder.GetInsertCommand();
DataTable objtable = objDatasSet.Tables["USE"];
DataRow objRow = objtable.NewRow();
objRow["USE_Id"] = 2;
objRow["USE_Name"] = "易做图";
objRow["USE_Password"] ="6235540";
objtable.Rows.Add(objRow);
dgList.DataBind();
Response.Write(objAdapter.InsertCommand.CommandText);
在DataBind已经更新了。但是objAdapter.InsertCommand.CommandText输出的字符串竟然是一大堆问号。
数据库主键已经设了。
USE_Id字段是数字主键;
USE_Name字段是文本;
USE_Password字段也是文本; --------------------编程问答-------------------- 顶一下。期盼指教。。。。 --------------------编程问答-------------------- 由于是新手,没有多少分数给大家。。。。
补充:.NET技术 , C#