![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Programmer
Join Date: Sep 2007
Posts: 33
Rep Power: 0
![]() |
Wondering if I could get some pointers and or direction on how to create a database to be able to read/write to. I want to make a "Movie database" and not to sure on where to start.. Thanks
__________________
Slowly but surly trying to learn C#, SQL, VB.Net, and wondering if a tornado crosses the equator if it spins backwards.... |
|
|
|
|
|
#2 |
|
Professional Programmer
|
Re: Creating databases in c#
How about Creating databases in c#
__________________
Don't take life too seriously, it's not permanent ! |
|
|
|
|
|
#3 |
|
Hobbyist Programmer
Join Date: Mar 2005
Posts: 218
Rep Power: 4
![]() |
Re: Creating databases in c#
Xavier... wow that's genius, however did you come up with that solution
![]() Seriously... yeah, google search, decide on the database you want to use (MySql, SQLite, SQLServer etc etc) and then search more from there. |
|
|
|
|
|
#4 |
|
Programmer
Join Date: Sep 2007
Posts: 33
Rep Power: 0
![]() |
Re: Creating databases in c#
I tried that, but I was looking for like a basic layout. I know theres google and I have done that....
__________________
Slowly but surly trying to learn C#, SQL, VB.Net, and wondering if a tornado crosses the equator if it spins backwards.... |
|
|
|
|
|
#5 |
|
Resident Grouch
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jun 2005
Posts: 6,453
Rep Power: 10
![]() |
Re: Creating databases in c#
What do you currently know about databases and the construction thereof? I think it's a germane question, despite the plethora of libraries that purport to handle it all for you.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code. Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers |
|
|
|
|
|
#6 |
|
Programmer
Join Date: Sep 2007
Posts: 33
Rep Power: 0
![]() |
Re: Creating databases in c#
I know a little bit about SQL server 05
__________________
Slowly but surly trying to learn C#, SQL, VB.Net, and wondering if a tornado crosses the equator if it spins backwards.... |
|
|
|
|
|
#7 |
|
Hobbyist Programmer
Join Date: Mar 2005
Posts: 218
Rep Power: 4
![]() |
Re: Creating databases in c#
Okay, you confused me utterly...
Do you know anything about databases? Have you created one outside of C#? Basic layout for a program would be just SQL statements wrapped within either ExecuteQuery or ExecuteScaler or ExecuteNonQuery functions (if I recall my function names right). |
|
|
|
|
|
#8 | |
|
Programmer
Join Date: Sep 2007
Posts: 33
Rep Power: 0
![]() |
Re: Creating databases in c#
Quote:
OK, I know a little about c# and I know the basic SQL commands, but I am not sure how to be able to put a movie title into a txt box, hit save and have it save to a database or file so I can open it up at a later time and add, remove, or edit a movie title. I guess I am trying to figure out how to tie a c# application to a SQL database.. Hopefully that helps.
__________________
Slowly but surly trying to learn C#, SQL, VB.Net, and wondering if a tornado crosses the equator if it spins backwards.... |
|
|
|
|
|
|
#9 |
|
Omlette du fromage
Join Date: Oct 2007
Posts: 29
Rep Power: 0
![]() |
Re: Creating databases in c#
You need to look at an ADO tutorial (Active Data Objects) you need a connection string, a connection object, a command object and either a SQL string or (preferable) a stored procedure.
The connection string should be in your App.config file. The stored procedure with the Insert Sql statement and a @movietitle parameter should be in your SQL Server 2005 database that you create. When save is clicked you need to: Read in the connection string from app.config Create a connection object passing the connectionstring to the constructor Create a command object using the connection object's CreateCommand() method Set the Command objects CommandType to CommandType.StoredProcedure Set the Command object's CommandText to the name of the insert stored procedure you create in the database Use the COmmand object's parameters collection to add the movie title from the textbox declare an int variable open the connection using the connection object's Open() method Set the int variable just declared to = CommandObject.ExecuteNonQuery() Close the connection Return the int variable (it should equal 1 for one record inserted) There are many ways to tackle this problem with ADO the above is my preferred way. DONT bung all this in the click handler of the save button! (Well you can while you're getting to grips with ADO) but as soon as possible look to de-couple your data handling code from the UI. For example at it's simplest: Create a folder called DAL (For Data Access Layer) in solution explorer immediately below the project. Create a class file called Movie.cs, give the Movie class a string member variable called movieTitle. Create a public int method called InsertMovie() Put the above discussed ADO code in this method. When save is clicked on the form, Instantiate an instance of your new movie class: Movie movie = new Movie() movie.movieTitle = Textbox.Text; movie.InsertMovie(); Once you've grokked all that! you can think about: What if that movie title already exists in the database' movie table? Well it's easy cos we took the best practice approach. You simple put an If not exists sql statement in the InsertMovie stored procedure so it wont execute the insert if the title exists, this means ExecuteNonQuery will return 0 (no records inserted) you can check that return value in the Save button click handler and inform the user with a polite message. So you see? you haven't asked a small question. Database driven applications are a big area. Good luck. |
|
|
|
|
|
#10 | |
|
Programmer
Join Date: Sep 2007
Posts: 33
Rep Power: 0
![]() |
Re: Creating databases in c#
Quote:
HOLY COW!!! Thats what I was looking for. Thanks so much. I guess I wasn't clear in my original post, but you nailed it, I know their alot bigger than it seems, but thats why I needed some pointers and you definatly helped with the psuedocode essentially, Thanks
__________________
Slowly but surly trying to learn C#, SQL, VB.Net, and wondering if a tornado crosses the equator if it spins backwards.... |
|
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| creating an array of an object/class? | chillypacman | Java | 7 | May 31st, 2006 5:39 AM |
| Creating algorithms-> talent or experience? | Eric the Red | Other Programming Languages | 9 | Mar 1st, 2006 8:22 PM |
| Trying to setup an anti-cheat system for a game friend and I are creating | Dr.Backtick` | C++ | 14 | Feb 15th, 2006 11:12 PM |
| Java & Databases | krazyshane | Java | 2 | Dec 12th, 2005 10:50 PM |
| need guidance : on creating forms and shopping cart | gemini_shooter | HTML / XHTML / CSS | 3 | Oct 19th, 2005 11:27 PM |