0
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!

3
Contributors
7
Replies
8
Views
7 Years
Discussion Span
Last Post by __avd
0

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).

0

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!

0

Try this,

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

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!

0

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;
0

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!

0

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!

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.