OleDB Parameters

后端 未结 2 1288
面向向阳花
面向向阳花 2021-01-25 13:30

I have this access db that I have a ddl for the state name and a ddl for the year. I have a gridview that I\'d like to pass the value of the state drop down list into where cla

相关标签:
2条回答
  • 2021-01-25 13:45

    1.you need to open your connection

    2.you can add the parameter as follows

    public DataSet GetData()
    {
        DataSet ds;
        using (OleDbConnection conn = new OleDbConnection(connString))
        {
            string query= "select * from tblTest where location = ?";            
            using (OleDbCommand myCommand = new OleDbCommand(query, conn))
            {
    
                myCommand.Parameters.AddWithValue("@ddlStates", <your value>);
                conn.Open();
    
                using (OleDbDataAdapter da = new OleDbDataAdapter(myCommand, conn))
                {
                    ds = new DataSet();
                    da.Fill(ds, "Grades");
                    return ds;
                }
            }
    
        }
    }
    
    0 讨论(0)
  • 2021-01-25 14:05
    myCommand.Parameters.AddWithKey("location", this.ddlStates.SelectedValue);
    

    That assumes that the data type of the location column is textual. If it's numeric or something else then convert the SelectedValue to the appropriate data type first.

    0 讨论(0)
提交回复
热议问题