[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

C# Class to return datatable

Posted on 2014-03-27
1
Medium Priority
?
560 Views
Last Modified: 2014-05-20
Hi Experts

I'm new to C# I'm writing some code to return a datatable when a user passes a sql statement to a class, it's not working though as the class want's a sting returned.


 class SQL_Array
    {

        string SQL;
        DataTable results;

         public SQL_Array()
        {

        }

        public SQL_Array(string strSQL,DataTable result )
        {
            results = result;
            SQL = strSQL;
        }

        public string SQL_Results()
        {
           // string []SQL_Results;

            string SQL = "Select * from dmt.dbo.DIT_tblBlah where txtstaffid is not null";

            SqlConnection cnnDIT = new SqlConnection("Blah");
            cnnDIT.Open();

      

            SqlDataAdapter adap = new SqlDataAdapter(SQL, cnnDIT);

          // create an empty DataTable to hold the results
            DataTable results = new DataTable();

            // populate the DataTable. Note: the SqlDataAdapter will take care of opening/closing the connection for you
            adap.Fill(results);

            cnnDIT.Close();

            return results;

Open in new window

0
Comment
Question by:MrDavidThorn
1 Comment
 
LVL 75

Accepted Solution

by:
käµfm³d   👽 earned 2000 total points
ID: 39959513
Change the return type of the method:

public DataTable SQL_Results()
...

Open in new window

0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…
Suggested Courses

873 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question