代码:
protected void btn_news_delete_Click(object sender, EventArgs e)
{
//删除图片
string image_path = Server.MapPath("../../images/upload/news/") + Label_image_path.Text;
if (File.Exists(image_path))
{
File.Delete(image_path);
}
string strconn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Server.MapPath("../../App_Data/kasun.mdb");
OleDbConnection cn = new OleDbConnection(strconn);
cn.Open();
string sql_news_delete="DELETE FROM news WHERE news_id=@news_id";
OleDbCommand cm = new OleDbCommand(sql_news_delete, cn);
cm.Parameters.Add("@news_id", OleDbType.Integer);
cm.CommandType = CommandType.StoredProcedure;
cm.Parameters["@news_id"].Value = Convert.ToInt32(Label_news_id.Text.ToString());
int B=cm.ExecuteNonQuery();
if (B == 1)
{
cn.Close();
Response.Redirect("admin_news.aspx");
}
else
{
Label_result.Text = "删除新闻失败,请重试!";
}
}
发生的错误为:
EXECUTE 后需要有查询名称。
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。
异常详细信息: System.Data.OleDb.OleDbException: EXECUTE 后需要有查询名称。
源错误:
cm.Parameters["@news_id"].Value = Convert.ToInt32(Label_news_id.Text.ToString());
int B=cm.ExecuteNonQuery();
if (B == 1)
{
參考答案:cm.CommandType = CommandType.Text;