Jump to content
  • Advertisement
Sign in to follow this  
ididntdoit

database programming 101

This topic is 4007 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

(This could go in the .NET area, as alot has to do with that area, but it should be applicable outside .NET as well, so here goes...) Heres what Im using : C# in VS 2005 MySQL 5 A database (Ive created a database (testdb1) with a table (t1) that has a few fields (id, first, last). From the MySQL command prompt I can querry it and all that good stuff works fine.) Heres what Im trying to do : I have a console app I want to connect to the database. (It can work in a console right? lol) Heres a few questions : 1) ADO vs ODBC, whats the difference? (they are described to do the same thing) 2) When chosing a way to connect to a DB, will I need to have both these using System.Data.Odbc; using System.Data.OleDb; ? Or is that 2 different drivers that do essentially the same thing? 4) I think it all hinges on the connection string, which I have as con.ConnectionString="Provider=MySQLProv;Data Source=mysql;"; If I can wrap this all up and get my head around it, I will be writing up a C#/MySQL tutorial for GameDev if they want it, or just for my own benefit if they dont. It seems there is a *serious* amount of confusion about this topic from what Ive been reading. (So many options, and then you have to worry about ease of deployment, what files an end user might need, etc...) Some other points I would cover (that tripped me up for a bit, or helped alot) - copying the my.ini file to the WINDOWS directory - a trick to open a handy 'data link properties' menu with notepad - a SQL primer (I needed it, I was much more rusty than I thought) - a troubleshooting MySQL section to help get it up and you making tables - making a C# Windows app use a database If theres already one spot where this information can already be found, Id love to hear it. Especially if it has pictures along the way. //now watch this textarea eat all this when I hit submit...

Share this post


Link to post
Share on other sites
Advertisement
>> I have a console app I want to connect to the database. (It can work in a console right? lol)

Yes, you can use database connectivity with most programs, assuming you have the necessary programming experience and libraries.


>> 1) ADO vs ODBC, whats the difference? (they are described to do the same thing)

ODBC: A vendor independent database API first appearing in 1993. It is very well supported across a wide range of vendors, systems, and languages.

ADO: Microsoft's database API appearing in 1996. See also ADO.net. It is supported by Microsoft and a few other major corporations.

Both provide an API to run SQL queries on arbitrary databases. The implementations are very different.


If you are using C# as your language of choice, you should probably use ADO.NET unless you have a specific reason to use ODBC.

>> 2) When chosing a way to connect to a DB, will I need to have both these
>> using System.Data.Odbc;
>> using System.Data.OleDb;
>> ? Or is that 2 different drivers that do essentially the same thing?

You don't need either of those lines in your source code. The C# using statements are a convenience so you don't have to give the full scope of your functions. Delete one and recompile. If your compiler doesn't complain then you must not be using anything from within those namespaces.


You skipped question 3, just moving from question 2 to question 4. I'm not sure why you did that, but I assume you must have a good reason rather than being sloppy.

>> 4) I think it all hinges on the connection string, which I have as
con.ConnectionString="Provider=MySQLProv;Data Source=mysql;";

I don't see a question there, only a statement. Your connection string really has nothing to do with any of the questions you've asked so far. That particular connection string seems incomplete unless you are doing additional work later that could have been handled with a more complete connection string.


>> If I can wrap this all up and get my head around it, I will be writing up a C#/MySQL tutorial for GameDev if they want it, or just for my own benefit if they dont.

A generic C# database tutorial would probably be a good thing, but I'd prefer it to be written by somebody with a few years of actual professional database programming behind them. There are many people with those credentials on the board.

>> It seems there is a *serious* amount of confusion about this topic from what Ive been reading. (So many options, and then you have to worry about ease of deployment, what files an end user might need, etc...)

Yes, it does sound like you are confused. The confusion has to do with you, not with the topic itself.

There are many well-written books out there which can possibly clarify things for you. Some include "Database Programming with C#", "ADO.NET Examples and Best Practices for C# Programmers", "ADO.NET Cookbook", and "ADO.NET in a Nutshell".

If you need help with SQL itself there are countless books out there as well, choosing among them will depend on your own experience and usage needs.


>> Some other points I would cover (that tripped me up for a bit, or helped alot)
>> - copying the my.ini file to the WINDOWS directory
>> - a trick to open a handy 'data link properties' menu with notepad
>> - a SQL primer (I needed it, I was much more rusty than I thought)
>> - a troubleshooting MySQL section to help get it up and you making tables
>> - making a C# Windows app use a database
>> If theres already one spot where this information can already be found, Id love to hear it. Especially if it has pictures along the way.

These statements clearly indicate that you need to get cozy with some good books and work through the examples and programming problems they present.

Happy reading!

Share this post


Link to post
Share on other sites
"You skipped question 3, just moving from question 2 to question 4. I'm not sure why you did that, but I assume you must have a good reason rather than being sloppy."

Question 2 was made up of 2 questions.

"I don't see a question there, only a statement."

The statement was that there is a problem, probably having something to do with this connection string. The question was implied. (Turned out that was the problem. The connection string has to match up with the server youre using and the api you use.)

"A generic C# database tutorial would probably be a good thing, but I'd prefer it to be written by somebody with a few years of actual professional database programming behind them."

So would I but (turn sarcasm-o-matic on) people with years experience are good at looking at something with a newbies perspective. And they never skip over the obvious parts. And they make newbie mistakes and fall in newbie pitfalls and have to research, fix and document them. In my experience, a newbie writing a paper *that is reviewed by experts* is the best way to learn.

"Yes, it does sound like you are confused. The confusion has to do with you, not with the topic itself. "

Nice. Personal stab. Stay classy.

Truth is there are *many* posts scattered on the internet on this topic asking for information, and a vacuum of far reaching and thorough information sources. Thanks for posting a source where its all cleared up for everyone once and for all lol.

"These statements clearly indicate that you need to get cozy with some good books"

Currently reading David Chappells Understanding.NET (Old but good introduction to the material). I will be buying ADO in a nutshell now.



Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!