private void button1_Click(object sender, EventArgs e)
        {
            string m1;
            m1=cbmanganh.SelectedValue.ToString();
            myds1.DSPT.DefaultView.RowFilter  = "MaNganh='"+ m1 +"'" and "Nam ='" +tbnamhoc.Text + "'" and "HocKy ='" + tbhocky.Text + "'"and "KhoaHoc= '" +tbkhoahoc.Text + "'";
            dataGridView1.DataSource=myds1.DSPT.DefaultView;
        }

error: expected ";" after each "and"

Thank you so much!

For a conditional AND in C# we use the token &&
If in an expression, you want to point out that something is equal you use the == operator(equal) not the = operator(assignment).

thank you,ddanle.I used token && replace "and" but appear a error:

Error	1	Operator '&&' cannot be applied to operands of type 'string' and 'string'	D:\baitap huong dan\WindowsApplication3\WindowsApplication3\Form1.cs	43	49	WindowsApplication3

please help me!

Try this,

myds1.DSPT.DefaultView.RowFilter  = "MaNganh='"+ m1 +"'  and Nam ='" + tbnamhoc.Text + "'  and HocKy ='" + tbhocky.Text + "' and  KhoaHoc='" +tbkhoahoc.Text + "'";

Try this,

myds1.DSPT.DefaultView.RowFilter  = "MaNganh='"+ m1 +"'  and Nam ='" + tbnamhoc.Text + "'  and HocKy ='" + tbhocky.Text + "' and  KhoaHoc='" +tbkhoahoc.Text + "'";

thank you,adatapost!I tried,no error but when i press button,it don't show my data from database on datagrid!

Have you fill the dataset/datatable? Verify the database table's content.

DataView dv=myds1.DSPT.DefaultView;

dv.RowFilter  = "MaNganh='"+ m1 +"'  and Nam ='" + tbnamhoc.Text + "'  and HocKy ='" + tbhocky.Text + "' and  KhoaHoc='" +tbkhoahoc.Text + "'";

datagridview1.DataSource=dv;

Have you fill the dataset/datatable? Verify the database table's content.

DataView dv=myds1.DSPT.DefaultView;

dv.RowFilter  = "MaNganh='"+ m1 +"'  and Nam ='" + tbnamhoc.Text + "'  and HocKy ='" + tbhocky.Text + "' and  KhoaHoc='" +tbkhoahoc.Text + "'";

datagridview1.DataSource=dv;

Thank you,adatapost! it run successfully!

You're welcome.

I'm glad you got it working. Please mark this thread as solved if you have found an answer to your question and good luck!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.