0

我在 gridview 中有一个按钮字段,当我按下该按钮时,它从第一列获取 id 值,我在 select 语句中使用该 id 从表中获取数据,但我收到此错误“No Value Give For One或更多参数”

protected void grdData_SelectedIndexChanged(object sender, EventArgs e)
{
    GridViewRow row = grdData.SelectedRow;
    string id = row.Cells[1].Text;           

    try
    {
        conn.ConnectionString = conn_string;

        conn.Open();

        mySQLCommand.Connection = conn;
        mySQLCommand.CommandText = "Select [Movie_Description],[Movie_Image] from Movie_tbl where Movie_ID = @Movie_ID";
        mySQLCommand.Parameters.Add("@Movie_ID", OleDbType.VarChar).Value = id;

        myDataReader = mySQLCommand.ExecuteReader();

        if (myDataReader.Read())
        {

            txtDescription.Text = myDataReader["Movie_Description"].ToString();

        }
        else
        {
            txtDescription.Text = "No Such Movie";

        }

    }
    catch (Exception ex)
    {

        throw ex ;
    }

}
4

1 回答 1

0

我没有经常使用 mySQL,但我很确定您不需要OleDbType.VarChar参数。我还没有看到在 MS Access 之外使用过。尝试:

mySQLCommand.Parameters.AddWithValue("@Movie_ID", id);

如果失败,也许试试

mySQLCommand.Parameters.Add(new MySqlParameter("@Movie_ID", id));

mySQLCommandMySqlCommand是您的代码中的类型,对吗?

于 2013-01-18T20:42:53.303 回答