Hi Shud,
You need to handle the selected value before sending to the method.
I have used Sql Database. So i use Sql Client. You need to use OleDb client as you are using access database.
Check this example. Now please take its reference and correct your code.
Database
For this example I have used NorthWind database that you can download using the link given below.
Download Northwind Database
C#
private void btnSearch_Click(object sender, EventArgs e)
{
string country = cbCountry.SelectedItem != null ? cbCountry.SelectedItem.ToString() : "";
dataGridView1.DataSource = GetComupterReportChainWise(txtCity.Text, country, txtTitle.Text);
}
public DataTable GetComupterReportChainWise(string city, string country, string title)
{
SqlConnection con = new SqlConnection();
con.ConnectionString = ConfigurationManager.ConnectionStrings[1].ConnectionString;
SqlDataAdapter adp = new SqlDataAdapter("select ContactName,ContactTitle,City,Country from Customers where ([City] = @City OR @City IS NULL) and ([Country] = @Country OR @Country IS NULL) and ([ContactTitle] = @Title OR @Title IS NULL)", con);
adp.SelectCommand.Parameters.AddWithValue("@City", !string.IsNullOrEmpty(city) ? city : (object)DBNull.Value);
adp.SelectCommand.Parameters.AddWithValue("@Country", !string.IsNullOrEmpty(country) ? country : (object)DBNull.Value);
adp.SelectCommand.Parameters.AddWithValue("@Title", !string.IsNullOrEmpty(title) ? title : (object)DBNull.Value);
DataTable dtp = new DataTable();
adp.Fill(dtp);
return dtp;
}
Screenshot
