0

我正在尝试根据这篇文章从访问数据库生成动态元标记。

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 ”。

4

1 回答 1

0

你说WHERE Title = @Title,但我看不到你在哪里为这个参数赋值。

SqlCmd = new OleDbCommand(query, myconnection); 
SqlCmd.Parameters.AddWithValue("@Title","a title");
于 2012-10-24T09:25:09.797 回答