Wednesday, July 27, 2005

ADO.NET Basics: Connecting to a DataBase

Ok, I have a big problem with ADO.NET. I don't seem to understand it very well. So in order to do so I am going to write little mini how-to's for ADO.NET. The first one is going to be connecting to a database. All my code will be in C#.

We are going to assume you have a SQL Server database and all commands will be against SQL Server. So be sure you impor the right namespace just so you can know it is:

using System.Data.SqlClient;

First we need to come up with the information that we are going to use to connect to the database. We are going to connect to the NorthWind database with User and the username and Password as the password.

So here is a generic connection string.

string ConnectionString = "server=myServer;uid=myUser;pwd=myPassword;database=DataBase"

Here is how we are going to customize it.

string ConnectionString = "server=myServer;uid=User;pwd=Password;database=NorthWind"

Next is constructing the connection.

SqlConnection Connection = new SqlConnection(ConnectionString);

You need to be sure that you take the string that you have the database information inside the parenthesis of the the SqlConnection command

Next is a very important step. Opening and closeing the connection.


See basically you take the name that you constructed it with and extend it use Open and Close.

So lets put all this together in one with a try catch block for error testing.

string ConnectionString = "server=myServer;uid=User;pwd=Password;database=NorthWind"

SqlConnection Connection = new SqlConnection(ConnectionString);


If you run that with against your databse inside of your web application you should have a blank page that says Hello. If not you will probably be looking at an error of some sort. Just use that screen to debug. This should also work in a windows forms application.

Tuesday, July 19, 2005

A revelation at last

I seem to be running into some trouble. Basically, I consider myself a newb at programming. Yes a newb. Not because I don't know anything, but because I have never actually made anything. I understand a lot of programming concepts of how to do certain things, but I have yet to actually sit down and make an application of my own. Yes, I made that notepad program, but that was mostly goofing around with one feature then it turned into something else.

No no my problem lies in the fact I don't believe in myself. Have you all ever run into that problem?

I think one thing that holds me up is I understand how to do a, b, and c, but when it comes to putting a and c together. I freak out because it requires that I know how to do d and e too. Well first off I have no frelling idea that I need to know d and e in the first place. Then when I do figure that out I just play with D and E seperately, but am afraid to venture out and put them together with A and C.

I guess the saying "nothing ventured, nothing gained" falls into this. I think my biggest fear is failure not from an aspect of a project, but in life. I feel that if I do fail at programming then nothing will matter after that, and since I have spent my last several years working for this goal I will feel it a waste.

I offered to help do the blockengine because I figured hey something I can work on that will be fun and that I can actually figure out because others will be there to help, but as before I find that I have run into the problem that I need D and E, but I don't know what they are or where to look.

This is a tormenting problem that has been going through my head for the last couple of weeks. I think it is time for me to stand up to myself. I realize I am a coward, and I need to change.

Has anyone else gone through this at all or am I alone once more out on that dreadful limb?

Buddy Lindsey

Tuesday, July 12, 2005

DataReader w00t

Hey everyone.

I finally figured out how to use the DataReader. For those of you that still don't realize that I am a newb, well I am. By me figureing out this one thing it has made a lot of concepts "click" for me. I can actually do some things that I honestly had no idea how to do before. For example I can use a querystring with the ID of something lets say a post. Throw that querystring into a SQL Statement and get out the information just for that post. The biggest problem with my code right now is that it is open for a SQL injection attack, but now that I understand what in the world I am doing with the datareader I can easily fix that problem.

I am so excited. This is why I love to code. It is such an adreneline rush when you figure out something that has been tormenting you for a long time, and you absolutly know that you should fundamentaly understand and be able to use it in anyway.

So in closing I did it, I did it. WooHoo

Can you tell I am excited.

Thank you,
Buddy Lindsey

p.s. I will post a minihow-to within the next couple of days on using the DataReader.

Monday, July 11, 2005

Newbs can come here.

I have recently talkd to a guy in the DotNetRocks chatroom during the latest DNR live show, and he told me that he learns to do certain tasks by writing an article over it.

So I have decided to do the same thing. I will post little explanations of basic things here on my blog such as how to use query strings, session state variables etc. These are things that took me reading several sites to understand so I will attemt to explain it once so new developers will get it the first time.

Leave your feedback on any ideas.

Buddy Lindsey

Sunday, July 10, 2005

Too many options?

I was just reading some RSS feeds that I am subscripbed too and this caught my eye.

This is very true in ASP.NET there are so many options that you can have a hard time decideing what you want to do. In the case of the post do you use several user controls on a single page or several pages?

Another question is do you use a DataGrid, DataList, or a repeater?
While the answer would be easy to see by a developer that is use to ASP.NET it is not to a newb like me.

Take something I want to do for example, which I still can't seem to figure out how to do. I want to make a category table in a database, and a links table in a database where each link is categorized by the category table. In my code I want it to be completely dynamic. Basically it grabs all the categories out of the categories table, and all the links out of the links table. Once they are retrieved they are displayed under each categories title like:


Search Engines

That is how I want it displayed, but I don't want to hard code anything. In a way like a CMS (Content Managment System).

This is definatly a problem that I see with ASP.NET. Once I learn more in ASP.NET I am going to try to write up articles on how to decide between these many features. This is definatly where the power is in ASP.NET. When you can use the all these features in your development process then you can create awesome websites.

Again this is a good reason for a grok site for ASP.NET.

Any Ideas?

Buddy Lindsey

Tuesday, July 05, 2005

Hello, this isn't really .NET related, but it is a project that I am currently working on with some people at You see a while back Buzz from released some C++ VTM's(Video Training Modules). I must say they were awesome video tutorials. Well I watched some of them and learned a lot about C++ so now I am joining this project which is to be based on all the knowledge that you get mainly from We are hoping that it is a success. So far we are in the planning stages and haveing a lot of fun.

It is going to be a 2d based graphics engine. We are doing this purely for educational purposes. We do not intend to put any other engines to shame, though that would be cool if we did. It will be an Open Source project so anyone can get the code for it and play. Any way check it out.

Also, once we get this done. I amg oing to see how long it takes to port it to the .NET framework just for jollies.

Buddy Lindsey