How to use databases in C#

simplyme

Junior Member
Mar 6, 2009
24
0
0
I want to use databases in C# so that I can implement a history feature in my web browser program.

The things that I need to store include strings about the site and a snapshot of the page. I've tried refering other sites and I couldn't get what they were trying to say.

Can someone explain how this databases thing works in C#? In a simpler way?
 

Ken g6

Programming Moderator, Elite Member
Moderator
Dec 11, 1999
16,700
4,661
75
First, can you explain some more of what you're trying to do with a database? Are you making a web page with ASP.NET, or are you making a web browser, improving some example web browser from Microsoft?
 

zebano

Diamond Member
Jun 15, 2005
4,042
0
0
ok a database is a system that stores, sorts & retrieves data. Which one are you using? Are you using a relational database (the most common kind) or something else? If you're literally just storing a string and an image, you could use a filesystem but then you have to correlate the two and it's probably not as efficient as a database.

I suggest you download either SQL Server express edition or mySql (both free) and look for some tutorials about them (hopefully using C#).
 

simplyme

Junior Member
Mar 6, 2009
24
0
0
I'm trying to make my own web browser. What I want to store in my program is address of the site visited, the last time this site was viewed and a snapshot of the page that has just finished loading.

Each time a page has finished loading, I want to refer the records again and see If the page loaded has already been recorded. If so, then I just need to change the last viewed field.

If I'm writing this data to a file, the editing a record part ( If the record already exists ) I'm not sure how to go about it. When I went reading some books they said something about databases in C#. I thought that it could be more useful, in case I need to put more data into the records and if I could give the user the choice on how to view the history ( by date, by alphabetical order, etc. )
 

simplyme

Junior Member
Mar 6, 2009
24
0
0
About this databases thing, I'm not sure If it means much, but I'm using Microsoft visual C# 2008 express edition. I think that means I can't use all the features or something in making databases, right?
 

PhatoseAlpha

Platinum Member
Apr 10, 2005
2,131
21
81
Databases are independent programs. C# does not make databases. It can connect to a database, but it is not one.

They are a huge subject, and not something we can realistically hope to show you how to use in a few forum posts.
 
Oct 27, 2007
17,009
5
0
Download Microsoft SQL Server Express Edition (it might come with Visual C# EE, I forget). The Express Edition of Visual Studio doesn't have the full suite of data access technologies available to the C# programmer built in, but everything is available through code (just not with the fancy OR mapping tools ect). Like PhatoseAlpha said, it's too big of a subject to explain in a forum post, but for .NET programming I suggest doing some web searches for LINQ to SQL and ADO.net Entity Framework, these are in my opinion the best options for mapping objects to relational data currently available in .NET.
 

CoinOperatedBoy

Golden Member
Dec 11, 2008
1,809
0
76
Realistically, would you want to use a database to store user browsing history? Why not a simple XML file in a local directory?
 

Nothinman

Elite Member
Sep 14, 2001
30,672
0
0
Realistically, would you want to use a database to store user browsing history? Why not a simple XML file in a local directory?

Because XML sucks? I'd rather the data be stored in a SQLite file than XML.
 

JasonCoder

Golden Member
Feb 23, 2005
1,893
1
81
Originally posted by: PhatoseAlpha
Databases are independent programs. C# does not make databases. It can connect to a database, but it is not one.

They are a huge subject, and not something we can realistically hope to show you how to use in a few forum posts.

Whoa now little feller, C# can make databases just fine. Not sure why you'd want to but that's not saying that it can't.
 

VinylxScratches

Golden Member
Feb 2, 2009
1,666
0
0
Originally posted by: Nothinman
Realistically, would you want to use a database to store user browsing history? Why not a simple XML file in a local directory?

Because XML sucks? I'd rather the data be stored in a SQLite file than XML.

From what I understand, when you load a XML file, the whole thing has to be loaded into memory so if it does get big it can take a toll on your system.

I believe SQLite is used by Firefox.
 

Nothinman

Elite Member
Sep 14, 2001
30,672
0
0
From what I understand, when you load a XML file, the whole thing has to be loaded into memory so if it does get big it can take a toll on your system.

I'm sure there are ways around that, I can't believe every XML library would force you to read the whole thing in at once.
 

JasonCoder

Golden Member
Feb 23, 2005
1,893
1
81
Originally posted by: Nothinman
From what I understand, when you load a XML file, the whole thing has to be loaded into memory so if it does get big it can take a toll on your system.

I'm sure there are ways around that, I can't believe every XML library would force you to read the whole thing in at once.

Yep, which is why SAX parsers came into being. .Net does a similar deal with stream readers, etc.
 

Krioni

Golden Member
Feb 4, 2000
1,371
0
71
Wow... as a C# developer it's amazing to me that you're developing a web browser and don't have any idea about database development/integration. Are you just getting into development? Please don't read any tone into my statement or question, I'm just curious because from my experience (10 years as a professional dev) it's hard to think of someone who is willing to tackle a web browser not having run into a situation where they needed a data-aware application.
 

simplyme

Junior Member
Mar 6, 2009
24
0
0
I'll be frank, I'm just doing this as a hobby. I'm not a 25+ year old programmer or anything, just a student.

SQL lite sounds interesting, is it easy to learn? And about XML idea, is it possible to rearrange the data so I can display it to user's requirements? I always thought that XML was specially rearranged text to define stuff.
 

Krioni

Golden Member
Feb 4, 2000
1,371
0
71
Originally posted by: simplyme
SQL lite sounds interesting, is it easy to learn? And about XML idea, is it possible to rearrange the data so I can display it to user's requirements? I always thought that XML was specially rearranged text to define stuff.

You can query XML in a very similar fashion to a database. XML is pretty much wide open, so you can store data in XML as you please (assuming well-formedness, adherence to schema, etc.).

I would think that you would arrange (sort, format, etc.) the data when it is presented to the user. So, you can store it as you see fit (hopefully in a very efficient way) and allow the presentation layer of the application to present the information as it sees fit. Make sense?

With all of that said... it sort of depends what's important to you in your application. Is it portability? Is it performance? If you're just doing this as a way to learn, I suppose neither of those will be terribly important... but as you get into programming more those considerations, and many many others, will become important.

Good Luck!