要打印我的报告,我需要使用相同的材料类型和交货日期等搜索少量材料。
所以我决定创建一个名为" REPORTS"的新表单。然后在里面我添加了4个标签和2个文本框和2个DateTimePicker和1个按钮以及1个DataGridView
标签名称:
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"
按钮
button1="SEARCH"
的DataGridView
DataGridView1="myDataGrid"
我的数据库
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);
}
}
然后我将它添加到公开报告()
public Reports()
{
InitializeComponent();
datagridviewONE();
}
这里是问题
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;
}
没有错误,但我总是收到指向此代码的警告
bs.Filter = "material_class,material_type,last_delivery_date like '%" + m_class.Text + "%','%" + m_type.Text + "%','%" + start_date.Text + "%'";
你觉得这个问题怎么样?
答案 0 :(得分:1)
bs.Filter = "material_class,material_type,last_delivery_date like '%" + m_class.Text + "%','%" + m_type.Text + "%','%" + start_date.Text + "%'";
更改为
bs.Filter = "material_class like '%" + m_class.Text + "%' and
material_type '%" + m_type.Text + "%' and
last_delivery_date '%" + start_date.Text + "%'";
答案 1 :(得分:0)
我刚刚解决了问题,谢谢你“豆腐”帮助我 这是代码
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;
而不是使用OR我使用AND