to print my report I need to search few materials with the same material TYPE and Date of delivery etc.
so I decided to create a new form named "REPORTS" then inside it i added 4 labels and 2 textbox and 2 DateTimePicker and 1 button and 1 DataGridView
label names:
label1 = "Material type:"
label2 = "Material Class"
label3 = "start Date"
label4 = "end Date"
TEXTBOXS
textbox1="material Type"
textbox2="material class"
DATETIMEPICKER
datetimepicker1="Start date"
datetimepicker2="End date"
BUTTON
button1="SEARCH"
DATAGRIDVIEW
DataGridView1="myDataGrid"
my database
void DGview()
{
string Constring = "datasource = localhost;port=3306;username=root;password=mysqlpassword";
MySqlConnection conDatabase = new MySqlConnection(Constring);
MySqlCommand cmddatabase = new MySqlCommand("select * from albany1_b1l1.civil_materials;", conDatabase);
try
{
MySqlDataAdapter sda = new MySqlDataAdapter();
sda.SelectCommand = cmddatabase;
DataTable dbdataset = new DataTable();
sda.Fill(dbdataset);
BindingSource bSource = new BindingSource();
bSource.DataSource = dbdataset;
myDataGrid.DataSource = bSource;
sda.Update(dbdataset);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
then I added it to public report()
public Reports()
{
InitializeComponent();
datagridviewONE();
}
here's the PROBLEM
in the button1
private void SEARCH_Click(object sender, EventArgs e)
{
BindingSource bs = new BindingSource();
bs.DataSource = myDataGrid.DataSource;
bs.Filter = "material_class,material_type,last_delivery_date like '%" + m_class.Text + "%','%" + m_type.Text + "%','%" + start_date.Text + "%'";
myDataGrid.DataSource = bs;
}
no error but I always receive a warning that is pointing to this codes
bs.Filter = "material_class,material_type,last_delivery_date like '%" + m_class.Text + "%','%" + m_type.Text + "%','%" + start_date.Text + "%'";
what do you think is the problem?
bs.Filter = "material_class,material_type,last_delivery_date like '%" + m_class.Text + "%','%" + m_type.Text + "%','%" + start_date.Text + "%'";
change to
bs.Filter = "material_class like '%" + m_class.Text + "%' and
material_type '%" + m_type.Text + "%' and
last_delivery_date '%" + start_date.Text + "%'";
I just solved the problem thank you "tofu" for helping me here's the code
BindingSource bs = new BindingSource();
bs.DataSource = myDataGrid.DataSource;
bs.Filter = "material_description like '%" + m_description.Text + "%' AND material_type like '%" + m_type.Text + "%'";
myDataGrid.DataSource = bs;
instead of using OR i use AND
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.