Click here to Skip to main content
14,601,122 members
Rate this:
Please Sign up or sign in to vote.
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;",
          Path.GetDirectoryName(filename1));
          
            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",
 Path.GetFileName(filename1));
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))
            {
                olconn.Open();
                OleDbDataAdapter adapter = new OleDbDataAdapter();
                adapter.SelectCommand = new OleDbCommand(cmdstring, olconn);
                adapter.SelectCommand= new OleDbCommand(cmdstring1, olconn);
                adapter.SelectCommand= new OleDbCommand(cmdstring2, olconn);
                dataset.Clear();
                adapter.Fill(dataset, "Test");
                olconn.Close();
            }
            return dataset;
        }
        public void Process_Click(object sender, EventArgs e)
        {
            
           
            try
            {
                DataSet dataset = Form1.Getdataset1(Locations.Text);
                Datagidveiw1.DataSource = dataset.Tables[0].DefaultView;
             
              
            }
            catch (System.Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
    }
}


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
Posted
Updated 22-Nov-10 0:26am
v2
Comments
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

Rate this:
Please Sign up or sign in to vote.

Solution 1

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.
   

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




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100