Im trying to get data in data grid view . this code works fine if i use this query :- "Select * from employee.transaction"
But when im trying to put the conditions it does not give any output (just shows a blank table)
My table has month,year column of type Int.Im using mysql server 5.6.25
I cant find the problem with my code.Please help.Thx in advance.
private void load_data_Click(object sender, EventArgs e)
{
string constring = "datasource = localhost;port = 3306;username = ****;password = ****";
MySqlConnection conDataBase = new MySqlConnection(constring);
var cmdDataBase = conDataBase.CreateCommand();
cmdDataBase.CommandText = @"select * from employee.transaction where department = @department AND month = @month AND year = @year";
cmdDataBase.Parameters.AddWithValue("@department", this.department.Text);
cmdDataBase.Parameters.AddWithValue("@month", this.dateTimePicker1.Value.Month);
cmdDataBase.Parameters.AddWithValue("@year", this.dateTimePicker1.Value.Year);
try
{
// here im trying to show table in datagrid view
MySqlDataAdapter sda = new MySqlDataAdapter();
sda.SelectCommand = cmdDataBase;
DataTable dbdataset = new DataTable();
sda.Fill(dbdataset);
BindingSource bSource = new BindingSource();
bSource.DataSource = dbdataset;
dataGridView1.DataSource = bSource;
sda.Update(dbdataset);
//here im trying to make a excel file which would contain what is currently being displayed in the datagrid view
DataSet ds = new DataSet("New_DataSet");
DataTable dt = new DataTable("New_DataTable");
dt.Locale = System.Threading.Thread.CurrentThread.CurrentCulture;
ds.Locale = System.Threading.Thread.CurrentThread.CurrentCulture;
ds.Tables.Add(dbdataset);
ExcelLibrary.DataSetHelper.CreateWorkbook("MyExcelFile.xls", ds);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}