0

i need to ask one more question....

private void bbn_Click(object sender, EventArgs e)
        {
            OleDbDataAdapter ad;
            DataSet ds1 = new DataSet();
            
            if (comboBox1.SelectedIndex == 0)
            {
                string str1 = "select * from '"+comboBox1.SelectedIndex+"'";
                OleDbConnection conn1 = new OleDbConnection(str);
                ad = new OleDbDataAdapter(str1, conn1);

                ad.Fill(ds1);
                dataGridView1.DataSource = ds1.Tables[0].DefaultView;

i want the button to select the data from combo box and then display the corresponding table in grid view...

however its giving me an error

ad.Fill(ds1)

here...

it says syntax error..i know i need to write table name there...but i want it to read it from my

combobox.seleted index

....

Any suggestions....


thanks and regards

2
Contributors
1
Reply
2
Views
6 Years
Discussion Span
Last Post by jay.gadhavi
0

You have written

comboBox1.SelectedIndex

Well, this gives you a selected index, whtever you have selected like 1, 2 or 4

Well, same table name 1, 2, or 4 might be not availabe in your database

so use .SelectedValue

so you may get the table name form the combobox

check it out and ...

Regards,
jay

Edited by Ezzaral: Snipped url. Please restrict personal links to your user signature.

This topic has been dead for over six months. 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.