Click here to Skip to main content
15,921,028 members
Home / Discussions / C#
   

C#

 
Generalhelp me please i really cant solve it Pin
nidhelp23-Aug-05 21:50
nidhelp23-Aug-05 21:50 
GeneralRe: help me please i really cant solve it Pin
Colin Angus Mackay23-Aug-05 22:39
Colin Angus Mackay23-Aug-05 22:39 
GeneralRe: help me please i really cant solve it Pin
nidhelp23-Aug-05 23:07
nidhelp23-Aug-05 23:07 
GeneralRe: help me please i really cant solve it Pin
Colin Angus Mackay23-Aug-05 23:15
Colin Angus Mackay23-Aug-05 23:15 
GeneralRe: help me please i really cant solve it Pin
nidhelp23-Aug-05 23:33
nidhelp23-Aug-05 23:33 
GeneralRe: help me please i really cant solve it Pin
Colin Angus Mackay23-Aug-05 23:52
Colin Angus Mackay23-Aug-05 23:52 
GeneralRe: help me please i really cant solve it Pin
nidhelp24-Aug-05 6:12
nidhelp24-Aug-05 6:12 
GeneralRe: help me please i really cant solve it Pin
Colin Angus Mackay24-Aug-05 13:13
Colin Angus Mackay24-Aug-05 13:13 
There are many ways to do this. One of the correct ways is to create a DAL (Data Abstraction Layer) in your application. This is really just a class, or set of classes (if your application is big) that communicates with the database for you. It then returns the data to what ever part of the application needed it.

e.g.

class Dal
{
    private string connectionString;
    public Dal()
    {
        connectionString = ConfigurationSettings.AppSettings["connectionString"];
    }
 
    private SqlConnection Connection
    {
        get
        {
            return new SqlConnection(connectionString);
        }
    }
 
    // Example of returning a single row.
    public Hashtable GetMyData()
    {
        // Some code that accesses the database and gets the data through a datareader
        // see previous forum post for an example.
        Hashtable result = new Hashtable();
        for(int i=0; i<myDataReader.FieldCount;i++)
        {
            string columnName = myDataReader.GetName(i);
            object columnValue = myDataReader.GetObject(i);
            result[columnName] = columnValue;
        }
        return result
    }
}


Then somewhere in the code that needs the data from the database you can write something like this:
Dal dal = new Dal();
Hashtable data = dal.GetMyData();
// Do something with data (e.g. populate controls)


Does this help?


My: Blog | Photos
WDevs.com - Open Source Code Hosting, Blogs, FTP, Mail and More


GeneralRe: help me please i really cant solve it Pin
tatchung24-Aug-05 15:23
tatchung24-Aug-05 15:23 
GeneralRe: help me please i really cant solve it Pin
tatchung24-Aug-05 16:35
tatchung24-Aug-05 16:35 
GeneralRe: help me please i really cant solve it Pin
nidhelp24-Aug-05 20:24
nidhelp24-Aug-05 20:24 
GeneralRe: help me please i really cant solve it Pin
nidhelp24-Aug-05 23:39
nidhelp24-Aug-05 23:39 
AnswerRe: help me please i really cant solve it Pin
Muammar©11-Nov-06 21:18
Muammar©11-Nov-06 21:18 
GeneralListboxes to datasets Pin
towneytowney23-Aug-05 21:47
towneytowney23-Aug-05 21:47 
GeneralListboxes to datasets Pin
towneytowney23-Aug-05 21:46
towneytowney23-Aug-05 21:46 
GeneralSystem.NullReferenceException Pin
oneyard23-Aug-05 21:34
oneyard23-Aug-05 21:34 
GeneralRe: System.NullReferenceException Pin
Colin Angus Mackay23-Aug-05 21:50
Colin Angus Mackay23-Aug-05 21:50 
GeneralRe: System.NullReferenceException Pin
oneyard23-Aug-05 22:09
oneyard23-Aug-05 22:09 
GeneralRe: System.NullReferenceException Pin
Colin Angus Mackay23-Aug-05 22:17
Colin Angus Mackay23-Aug-05 22:17 
GeneralRe: System.NullReferenceException Pin
leppie23-Aug-05 21:57
leppie23-Aug-05 21:57 
GeneralRe: System.NullReferenceException Pin
Guffa23-Aug-05 22:14
Guffa23-Aug-05 22:14 
GeneralRe: System.NullReferenceException Pin
V.24-Aug-05 0:49
professionalV.24-Aug-05 0:49 
GeneralRe: System.NullReferenceException Pin
V.24-Aug-05 0:53
professionalV.24-Aug-05 0:53 
GeneralNetwork Management Pin
Member 199534123-Aug-05 21:27
Member 199534123-Aug-05 21:27 
QuestionHow to listen connection request on 80 port Pin
Gagan Deep Singla23-Aug-05 19:45
Gagan Deep Singla23-Aug-05 19:45 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.