Solved

C# Class to return datatable

Posted on 2014-03-27
1
522 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 500 total points
ID: 39959513
Change the return type of the method:

public DataTable SQL_Results()
...

Open in new window

0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

770 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