我正在尝试根据这篇文章从访问数据库生成动态元标记。
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: Parameter @Title has no default value ”。