62,270
社区成员
发帖
与我相关
我的任务
分享
OleDbCommand updateCmd = new OleDbCommand();
//不知道where后面的id如何添加参数
updateCmd.CommandText = "update articles set [title]=?,[author]=?,[content]=? where id = ?";
updateCmd.CommandType = CommandType.Text;
updateCmd.Connection = conn;
updateCmd.Parameters.Add("?", OleDbType.VarWChar, 100, "title");
updateCmd.Parameters.Add("?", OleDbType.VarWChar, 10, "author");
updateCmd.Parameters.Add("?", OleDbType.VarWChar, 10000, "content");
adapter.UpdateCommand = updateCmd;
conn.Open();
using (OleDbTransaction tran = conn.BeginTransaction(IsolationLevel.ReadCommitted))
{
adapter.SelectCommand.Transaction = tran;
adapter.UpdateCommand.Transaction = tran;
try
{
DataRow updateRow = ds.Tables["articles"].Rows[id];//通过断点诊断,在这出错了:在位置216处没有任何行。
//以下没有执行----中间的行在诊断时跳过,直接catch错误了
updateRow["title"] = n_title;
updateRow["author"] = n_author;
updateRow["content"] = n_content;
adapter.Update(ds, "articles"); //我保证有articles这个表和ds这个DataSet
tran.Commit();
//以上没有执行
}
catch (Exception ex) //直接到这里了
{
try
{
tran.Rollback();//回滚了
}
catch (Exception exc)
{
JS.JScript.Alert(exc.Message);
}
JS.JScript.Alert(ex.Message);//抛出:在位置216处没有任何行,216行在access中,有数据的。
}
}
conn.Close();
JS.JScript.AlertAndRedirect("修改成功!", "news_mg.aspx"); OleDbCommand updateCmd = new OleDbCommand();
updateCmd.CommandText = "update articles set [title]=@title,[author]=@author,[quotedfrom]=@quotedfrom,[quotedlink]=@quotedlink,[subject]=@subject,[update]=@update,[content]=@content,[channel]=@channel,[lanmu]=@lanmu where id = @id";
updateCmd.CommandType = CommandType.Text;
updateCmd.Connection = conn;
// OleDbParameter parmUpdPk = adapter.UpdateCommand.Parameters.Add("@id", OleDbType.Integer, 4, "id");
// parmUpdPk.SourceVersion = DataRowVersion.Original;
updateCmd.Parameters.Add("@title", OleDbType.VarWChar, 100).Value=n_title;
updateCmd.Parameters.Add("@author", OleDbType.VarWChar, 10).Value=n_author;
updateCmd.Parameters.Add("@quotedfrom", OleDbType.VarWChar, 20).Value=quotedfrom;
updateCmd.Parameters.Add("@quotedlink", OleDbType.VarWChar, 100).Value=quotedlink;
updateCmd.Parameters.Add("@subject", OleDbType.VarWChar, 10).Value=subject;
updateCmd.Parameters.Add("@update", OleDbType.DBTimeStamp, 40).Value=string.IsNullOrEmpty(n_date) ? DateTime.Now.ToString() : n_date;
updateCmd.Parameters.Add("@content", OleDbType.VarWChar, 10000).Value=n_content;
updateCmd.Parameters.Add("@channel", OleDbType.VarChar, 10).Value=channel;
updateCmd.Parameters.Add("@lanmu", OleDbType.VarChar, 20).Value=lanmu;
updateCmd.Parameters.Add("@id", OleDbType.Integer).Value=id;
adapter.UpdateCommand = updateCmd;
conn.Open();
using (OleDbTransaction tran = conn.BeginTransaction(IsolationLevel.ReadCommitted))
{
adapter.SelectCommand.Transaction = tran;
adapter.UpdateCommand.Transaction = tran;
try
{
adapter.UpdateCommand.ExecuteNonQuery();
tran.Commit();
}
catch (Exception ex)
{
try
{
tran.Rollback();
}
catch (Exception exc)
{
JS.JScript.Alert(exc.Message);
}
JS.JScript.Alert(ex.Message);
}
}
conn.Close();
JS.JScript.AlertAndRedirect("修改成功!", "news_mg.aspx");
OleDbCommand updateCmd = new OleDbCommand();
//不知道where后面的id如何添加参数
updateCmd.CommandText = "update articles set [title]=@title,[author]=@author,[content]=@content where id = @id";
updateCmd.CommandType = CommandType.Text;
updateCmd.Connection = conn;
updateCmd.Parameters.Add("@title", OleDbType.VarWChar, 100, "title");
updateCmd.Parameters.Add("@author", OleDbType.VarWChar, 10, "author");
updateCmd.Parameters.Add("@content", OleDbType.VarWChar, 10000, "content");
updateCmd.Parameters.Add("@id", OleDbType.Int, 4, 123);
adapter.UpdateCommand = updateCmd;
conn.Open();
using (OleDbTransaction tran = conn.BeginTransaction(IsolationLevel.ReadCommitted))
{
adapter.SelectCommand.Transaction = tran;
adapter.UpdateCommand.Transaction = tran;
try
{
DataRow updateRow = ds.Tables["articles"].Rows[id];//通过断点诊断,在这出错了:在位置216处没有任何行。
//以下没有执行----中间的行在诊断时跳过,直接catch错误了
updateRow["title"] = n_title;
updateRow["author"] = n_author;
updateRow["content"] = n_content;
adapter.Update(ds, "articles"); //我保证有articles这个表和ds这个DataSet
tran.Commit();
//以上没有执行
}
catch (Exception ex) //直接到这里了
{
try
{
tran.Rollback();//回滚了
}
catch (Exception exc)
{
JS.JScript.Alert(exc.Message);
}
JS.JScript.Alert(ex.Message);//抛出:在位置216处没有任何行,216行在access中,有数据的。
}
}
conn.Close();
JS.JScript.AlertAndRedirect("修改成功!", "news_mg.aspx"); OleDbParameter parmUpdPk = adapter.UpdateCommand.Parameters.Add("?", OleDbType.Integer, 4, "id");
parmUpdPk.SourceVersion = DataRowVersion.Original;
我参考了如下链接,如法炮制的,看各位能否再给指条明路?
http://blog.csdn.net/gyming/article/details/17533237
https://msdn.microsoft.com/zh-cn/library/a94b9hed%28v=vs.80%29.aspx