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
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;
}
}
}
}
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.