我正在尝试通过选择另一个下拉列表列表值来填充下拉列表列表,但它在条件表达式中返回数据类型不匹配



条件表达式中的数据类型不匹配。 说明:执行 当前 Web 请求。请查看堆栈跟踪以获取更多信息 有关错误及其在代码中起源位置的信息。

异常详细信息:System.Data.OleDb.OleDbException:条件表达式中的数据类型不匹配。

源错误:

Line 77:             int Subject_ID = Convert.ToInt32(DropDown_SubjectName.SelectedValue);
Line 78:             OleDbCommand cmd = new OleDbCommand("select * from Assignment_Details where Subject_ID = " + Subject_ID, con);
Line 79:             cmd.ExecuteNonQuery();
Line 80:             cmd.CommandType = CommandType.Text;
Line 81: 

public partial class WebForm2 : System.Web.UI.Page
{
    OleDbConnection con = new OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=E://Project//VirtualClassRoomDB//VirtualClassroomDB.accdb");
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            BindSubjectdropdown();
        }
    }
    protected void BindSubjectdropdown()
    {
        //conenction path for database
        con.Open();
        OleDbCommand cmd = new OleDbCommand("select * from Subject_Details", con);
        cmd.CommandType = CommandType.Text;
        try
        {
            con.Open();
            cmd.ExecuteNonQuery();
            con.Close();
        }
        catch
        {
        }
        OleDbDataAdapter da = new OleDbDataAdapter(cmd);
        DataSet ds = new DataSet();
        da.Fill(ds);
        DropDown_SubjectName.DataSource = ds;
        DropDown_SubjectName.DataTextField = "Subject_Name";
        DropDown_SubjectName.DataValueField = "Subject_ID";
        DropDown_SubjectName.DataBind();
        DropDown_SubjectName.Items.Insert(0, new ListItem("--Select--", "0"));
        DropDown_AssignmentName.Items.Insert(0, new ListItem("--Select--", "0"));
    }
    protected void Button_Ass_Add_Click(object sender, EventArgs e)
    {
        OleDbCommand cmd = new OleDbCommand("insert into Assignment_Details(Assignment_Name,Assignment_Description,Subject_ID,Upload_by,Assignment_Path) values('" + TextBox_AssignementName.Text + "','" + TextBox_AssignmentDescription.Text + "','" + DropDown_Subject.SelectedValue + "','Maths','" + FileUpload_Assignment.FileName + "')", con);
        cmd.CommandType = CommandType.Text;
    }
    protected void DropDown_SubjectName_SelectedIndexChanged(object sender, EventArgs e)
    {
        con.Open();
        int Subject_ID = Convert.ToInt32(DropDown_SubjectName.SelectedValue);
        OleDbCommand cmd = new OleDbCommand("select * from Assignment_Details where Subject_ID = " + Subject_ID, con);
        cmd.ExecuteNonQuery();
        cmd.CommandType = CommandType.Text;
        OleDbDataAdapter da = new OleDbDataAdapter(cmd);
        DataSet ds = new DataSet();
        da.Fill(ds);
        DropDown_AssignmentName.DataSource = ds;
        DropDown_AssignmentName.DataTextField = "Assignment_Name";
        DropDown_AssignmentName.DataValueField = "Assignment_ID";
        DropDown_AssignmentName.DataBind();
        DropDown_AssignmentName.Items.Insert(0, new ListItem("--Select--", "0"));
    }
}
cmd.ExecuteNonQuery(); 

不是你想要的。这就是运行操作查询而不是选择查询的方式。你也有这行太晚了:

cmd.CommandType = CommandType.Text;

它应该在您执行查询之前显示。

相关内容

  • 没有找到相关文章

最新更新