Ideas For A SQL Connection Object Please

S

Steven C

Hello:

I now that this has been posted before, but I need a little guidance
on how to create a SQL connection class for my C# app. I saw an open
source variety on the web, but it's way complex for what I need right
now. I'm trying to cobble together my first app, and I need something
fairly simple.

I have several forms in the app, all of which need DataSets (to bind
to grids, etc), and I want to create an class to do the connection
string, data adapter fill, etc, by passing it a SQL string, and
getting a DataSet object returned. I want to separate the data access
layer from the forms if possible, so I don't have connection stuff
littering the forms.

Are there any fairly simple techniques, sample code or what have you,
that anyone can offer? For example, I'm just putzing around, and came
up with this:

using System;
using System.Data;
using System.Data.SqlClient;

namespace Conferro.Connections
{
/// <summary>
/// Summary description for Connections.
/// </summary>
public class Connections
{
public Connections()
{
//
// TODO: Add constructor logic here
//
}

public System.Data.DataSet m_getDataSet(string lcSql,string
lcTable)
{
System.Data.SqlClient.SqlConnection conn = new
SqlConnection("Data Source=SWC_K7\\CHRISMON1;User
Id=yadda;password=yadda;Initial
Catalog=ChrismonContacts");

DataSet NewDS = new DataSet();

SqlDataAdapter CustomersAdapter = new
SqlDataAdapter(lcSql,conn);

CustomersAdapter.Fill(NewDS,lcTable);

return NewDS;

}
}

Am I even close to being on the right track? Many thanks!

Steven
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top