Reputation: 1339
I am in the preparation stages of writing my first real program. I've designed a set of tables to store my financial data. I know
1) what data goes where in the tables
2) what relationships exist between tables and fields
3) what queries are needed
4) what the forms should look like to write data to the tables
5) what output I need and how it should be organized
I've decided on C#, with WPF for the GUI, and a SQL database for the data. If I understand correctly I'll be needing ADO.NET to interface with the SQL db. The problem for me is that right now I am only familiar with writing non-GUI C++ using text files (or the keyboard) for input.
I'm not desiring to become a programmer with varied and marketable skills, so I'd rather avoid spending time learning things that won't apply to this project. I'm looking for the most direct route from here to a useful working (and maintainable) program.
So that's the situation I need help with. Please let me know if I left out anything relevant.
My question is, what are the steps I need to take from here to get it done?
Thanks for your help.
Upvotes: 2
Views: 1902
Reputation: 65476
My suggestion to you is to first write your first prototype as a console/text program under the platform of choice. When you've got the input and output the way you want it - then ask again for refactoring help in getting the UI the way you want it. You can also get your db queries easily tested and you're using your existing skills more efficiently earlier on to get the functionality right but with a limited UI.
Your console program will then also be a verification that the GUI version of your program is working as expected.
Edit: Here is a simple program that reads a value from the database and puts it on the screen.
using System;
using System.Data;
using System.Data.SqlClient;
class Program
{
static void Main()
{
using (SqlConnection connection = new SqlConnection("Data Source=server;database=mydb; Integrated Security=SSPI"))
{
SqlCommand command = connection.CreateCommand();
command.CommandText = "SELECT CategoryID, CategoryName FROM dbo.Categories;";
try
{
connection.Open();
SqlDataReader reader = command.ExecuteReader();
// process each row one at a time
while (reader.Read())
{
// reader contains the row (reader[0] is first column, etc)
Console.WriteLine("\t{0}\t{1}", reader[0], reader[1]);
}
reader.Close();
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}
}
}
Use this (and the link from where I got another version of this) to help you through through ado.net initially. As an experience programmer you can see that if you follow this model you can create common functions that return data based on passed in queries. When you want to get tables of data back instead of simple values, I'd suggest moving from ExecuteReader to other data functions functions.
N.B. Generally I wouldn't suggest you start here - I'd suggest fluent NHbernate but that is bit more complex for a beginner and would be better after you understand the relationship your code (in .net) has to the DB and the data therein.
Also jsut had a thought. If you want to use another technology rather that SqlClient you can use Linq2Sql. Watch this video to see if its helpful.. In fact there are some very useful free videos on DimeCasts.net.
Upvotes: 2
Reputation: 4018
Starting a new answer cause my old doesn't apply to these very specific steps. This answer is in support of Preet Sangha's reply, but is intended to be more specific than any of us have yet been.
Start a console app and add a "using System.Data.SqlClient" line at the top of the app. You'll need to start with a Connection object, then a Command object. Experiment with executing queries using your command object. Try both an "insert" statement and a "select" statement. For the "select", you'll be getting something back from the database. Use a SqlDataReader (executeReader on the command) for this and experiment with pulling values out (reader.read() & getXXX where XXX is the type of data you want to retrieve). These should make you comfortable enough to get your arms around the problem and return with a more directed question.
Given how new you are to this, MSDN will be your best friend. This should help get ya started :) http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlconnection(VS.71).aspx
Upvotes: 2
Reputation: 4018
I'm not desiring to become a programmer with varied and marketable skills, so I'd rather avoid spending time learning things that won't apply to this project.
In that case, skip .Net. It'll take you time to learn it well enough to do a good job. Since you mentioned you have (perhaps minimal) C++ experience, I'd maybe use Qt instead with the aid of Qt Designer to layout the GUI. From that point the rest of the app should be much like the stuff you've already done.
Unless you know what your doing with .Net, you'll end up with wildly unmaintainable code very, very quickly. I blame Visual Studio for this. By default, it encourages a "drag this thingy here, drop that there, double click and write code" approach to coding that usually results in a horrendous mess.
If you insist that you want C#/.Net anyway, I encourage you to start at the backend and work your way forward. Take the time to model your entities and your data access and your business layer before you even think about GUI. You may even take this a step further and write two project. One would be your dll, containing business and data access logic. The other would be your executable, where you wire your UI events into the dll's api.
Good luck.
Upvotes: 1
Reputation: 3840
Do You have any document specifying what the application is going to do instead of a specification how thing are going to be done?
If you don't have that, then take a step back and write a Functional Specification. After you have that you might want to redo some of the work you already did.
You also should take a few moment's to think how are you going to ogranize your code. What namespaces and classes are you going to use. Where will you put the code for:
You should isolate those parts of your application to make it easier to maintain.
Upvotes: 1