我正在尝试根据此post从访问数据库生成动态元标记。
protected void Page_Load(object sender, EventArgs e)
{
OleDbParameter spar = new OleDbParameter("@Title", Request["Title"]);
string query = "SELECT * FROM storedata WHERE Title = @Title";
OleDbConnection myconnection = new OleDbConnection(ConfigurationManager.ConnectionStrings["accessConnectionString5"].ConnectionString);
OleDbCommand SqlCmd = null;
SqlCmd = new OleDbCommand(query, myconnection);
SqlCmd.Parameters.Add(spar);
SqlCmd.Connection.Open();
SqlCmd.ExecuteNonQuery();
OleDbDataAdapter ad = new OleDbDataAdapter(SqlCmd);
DataTable dt = new DataTable();
ad.Fill(dt);
title.InnerHtml = dt.Rows[0]["Title"].ToString();
keywords.Attributes.Add("content", dt.Rows[0]["Title"].ToString());
// Closing the SQL connection
SqlCmd.Connection.Close();
}
但我收到错误' System.Data.OleDb.OleDbException:参数@Title没有默认值'。
答案 0 :(得分:0)
您说WHERE Title = @Title
但我看不到您为此参数指定了值的位置。
SqlCmd = new OleDbCommand(query, myconnection);
SqlCmd.Parameters.AddWithValue("@Title","a title");