Jump to content

Connecting a database with an application

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
5 replies to this topic

#1
sebkom

sebkom

    Newbie

  • Members
  • Pip
  • 2 posts
So, basically, I am a total n00b. I have never tried connecting a database to a project before.

So, I am using C# for this simulator me and my friends are coding and we want to add a database to it. We have created it using Visual Studio 2010 but we have no idea what to do afterwards. Do we create an extra class to hold all the database stuff and then call its methods from whichever class we want?

The database is a .mdf, in case it's important.

#2
lobo521

lobo521

    Learning Programmer

  • Members
  • PipPipPip
  • 57 posts
I'm using DAO pattern. Java example: Core J2EE Patterns - Data Access Object.
You can implement it in C#.

#3
abdul.gafur

abdul.gafur

    Learning Programmer

  • Members
  • PipPipPip
  • 42 posts
DAO or ADO?

#4
lobo521

lobo521

    Learning Programmer

  • Members
  • PipPipPip
  • 57 posts
Check link.

#5
gokuajmes

gokuajmes

    Programming God

  • Members
  • PipPipPipPipPipPipPip
  • 518 posts
ok i am doing this whole stuff just for you so please pay attention

here is the psedocode:

1.Check if the connection persists for the database

2.Make the connection using the ,SQL connection Object

3.Use Dataset and DataTable for filling entries

4.Populate the data from the Dataset and DataTable to your desired control

more help will be provided on the request

#6
questionspoint

questionspoint

    Newbie

  • Members
  • PipPip
  • 15 posts
use LINQ.

create a dbml file in visual studio.
open it and click the Server explorer Link in there. it will open a panel on left side.
Add a new connection to your database.
Drag all the objects/tables to your dbml file
save the file

and you are almost done.
db is connected, now you need to query it
if you need the connection string, its in your web.config already when you save the dbml file.