473,324 Members | 2,002 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,324 software developers and data experts.

Ideas For A SQL Connection Object Please

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
Nov 16 '05 #1
1 1714
Hi Steven,

I think that the best solution for you is to use the Data Access Application
Block for .NET.
Version 3.0 was just released - check out
http://msdn.microsoft.com/library/de...ml/daab-rm.asp
for more info.

It looks like something very complex at first, but when you start working
with it, you'll find out that it's pretty straight-forward.

Cheers,
Branimir

--
Branimir Giurov
MCSD.NET, MCDBA
<Steven C> wrote in message
news:si********************************@4ax.com...
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

Nov 16 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Dmitry Karneyev | last post by:
Hi All! I've got an ado.net app with several win forms. In the first form (form1) I connect to DB and in other forms I use connection string generated by the form1 and stored in sqlconnection...
4
by: Rahul Anand | last post by:
Getting SQL Exception when trying to implement Connection based Trasaction using SQL Helper class. I am using the follwing function to execute my stored procs: -=-=-=- ExecuteScalar(ByVal...
13
by: Larry | last post by:
Hi I have asp.net programs. I used a very simple data transfer method by using URLs ¡°First.aspx¡± contents a line to send data to the ¡°second.aspx¡± page, for
35
by: Eric Sabine | last post by:
In my Finally block, I was using cn.close (where cn is an ADO.NET connection object, SQLConnection to be exact) and then I came across the following in some microsoft code. If Not cn Is Nothing...
26
by: Rajeev Tipnis | last post by:
http://support.microsoft.com/default.aspx?scid=kb;en- us;819450 Questions: 1) Is this patch (fix) applicable to the .NET 1.1 Framework as well? That is, if we have Framework 1.1 (On...
20
by: fniles | last post by:
I am using VB.NET 2003, SQL 2000, and SqlDataReader. As I read data from tblA, I want to populate tblB. I use SQLDataReader for both tables. I do not use thread. When I ExecuteReader on tblB, I...
20
by: fniles | last post by:
I am using VS2003 and connecting to MS Access database. When using a connection pooling (every time I open the OLEDBCONNECTION I use the exact matching connection string), 1. how can I know how...
1
by: =?Utf-8?B?VmVua2F0ZXNhbiBT?= | last post by:
Hi, I have a requirement of consuming a connection object returned from a COM component deployed in COM+ application. I have given the need for this requirement end of my query. My component...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.