|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using System.Data;
namespace T_SQL_Test_Platform
{
class DataAccess
{
private string strConnectionInfo = "";
private SqlConnection sqlConnection;
private SqlCommand sqlCommand;
public string Connect()
{
string strTemp = "";
strTemp = "Database=AdventureWorks;Data Source=localhost;Trusted_Connection=True";
return Connect(strTemp);
}
public string Connect(string strConnectionString)
{
try
{
//Assign the default connection string
strConnectionInfo = strConnectionString;
sqlConnection = new SqlConnection(strConnectionInfo);
sqlConnection.Open();
return "";
}
catch (Exception ex)
{
return ex.Message.ToString();
}
}
public string ReadData(string sql, ref DataSet returnData)
{
try
{
sqlCommand = new SqlCommand(sql, sqlConnection);
SqlDataAdapter da = new SqlDataAdapter(sqlCommand);
da.Fill(returnData);
da.Dispose();
return "";
}
catch (Exception ex)
{
return ex.Message.ToString();
}
}
public void Disconnect()
{
try
{
sqlCommand.Dispose();
}
catch { }
try
{
sqlConnection.Close();
}
catch { }
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
I am currently a Senior Software Developer at a company in Illinois called DeGarmo. My primary skills are in .NET, SQL, JavaScript, and other web technologies although I have worked with PowerShell, C, and Java as well.
In my previous positions, I have worked as a lead developer, professor and IT Director. As such, I have been able to develop software on a number of different types of systems and I have learned how to correctly oversee the overall direction of technology for an organization. I've developed applications for everything from machine automation to complete ERP systems.
I enjoy taking hard subjects and making them easy to understand for people unfamiliar with the topic.