Solved

C# Class to return datatable

Posted on 2014-03-27
1
539 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

732 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