MrDavidThorn
asked on
C# Class to return datatable
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.
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;
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.