Click here to Skip to main content
15,907,395 members
Please Sign up or sign in to vote.
3.00/5 (2 votes)
See more:
Hi Developer,
I am tring to run multiple sql statements in dataset.
My code is:
public static DataSet Getdataset1(string filename1)
            string Connectionstring = string.Format("Provider=Microsoft.Jet.OLEDB.4.0;Data Source={0};Extended Properties=Text;",
            string cmdstring = string.Format(@"select * FROM {0} order by IN_no desc,FIRST_DATE asc,END_DATE asc", Path.GetFileName(filename1));
            string cmdstring1 = string.Format(@"select * FROM {0} order by IN no desc,FIRST DATE asc,END DATE asc",
string cmdstring2 = string.Format(@"select * FROM {0} order by Pd_no desc,FIRST_DATE asc,END DATE asc", Path.GetFileName(filename1));
            DataSet dataset = new DataSet();
            using (OleDbConnection olconn = new OleDbConnection(Connectionstring))
                OleDbDataAdapter adapter = new OleDbDataAdapter();
                adapter.SelectCommand = new OleDbCommand(cmdstring, olconn);
                adapter.SelectCommand= new OleDbCommand(cmdstring1, olconn);
                adapter.SelectCommand= new OleDbCommand(cmdstring2, olconn);
                adapter.Fill(dataset, "Test");
            return dataset;
        public void Process_Click(object sender, EventArgs e)
                DataSet dataset = Form1.Getdataset1(Locations.Text);
                Datagidveiw1.DataSource = dataset.Tables[0].DefaultView;
            catch (System.Exception ex)

The error occurs when I want to sort data.

{"IErrorInfo.GetDescription failed with E_FAIL(0x80004005)."}

Actually I want to create a match condition between cmdstring and after match the headertext of columns and then only one sql statement is run to sort data.
How can I create that, any suggestions?
Please accept this request
Updated 22-Nov-10 0:26am
LittleYellowBird 22-Nov-10 6:27am    
Hi, you cannot expect people to 'coorect and write code for you', this forum is to provide help and advice, and I think it is more likely to antagonise people, so I changed your comment to 'any suggestions'. :)
Sunasara Imdadhusen 22-Nov-10 6:30am    
You should try yourself!!

1 solution

There is a tiny little bug in the cmdstring1 SQL statement. See if you can find themissing character. All you have to do is compare it to the line above it.

Oh, and a DataAdpapter can only hold ONE select query at a time. Your query is returning the last one only, not the other two. You have to execute a fill 3 seperate times to fill the dataset AND you have to make sure that each table returned has a different name so you're not overwriting the previous data with the new query.
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900