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

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

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.