SQL guide for a C# console program

XML, Perl, Python, and other languages can be discussed here, even if it isn't PHP (We might forgive you).

Moderator: General Moderators

Post Reply
Andromeda
Forum Newbie
Posts: 11
Joined: Thu Nov 08, 2007 5:40 am

SQL guide for a C# console program

Post by Andromeda »

Hello, I’m trying to make a little program for my work in C#, it shale check if some data in a sql database is correctly entered. Just a simple select, if ok do green color, if false do read color :D simple code.

This is also my "Do to learn" project :D I have just begun programming C#. I have programmed php sins 2001 witch means that I am not having a hard time understanding the C# syntax and code. But there is 1 thing that keeps bugging the hell out of me.
Why is it so hard to work with sql servers in C#? I fell like I’m banning my head into the wall while the guides I have found keeps screaming TABELADAPTER!!! GRIDVIEW!!! DATASET!!!! :D

Well does one of you guys know an easy to follow guide for using sql in a console program?
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


Actually, none of the mentionned classes are required to do sql db programming... Here is a little sample that calls an Oracle stored procedure...

[syntax="csharp"]
using (OracleConnection conn = new OracleConnection("User Id=u;password=p;Data Source=ORCL"))
{
 conn.Open();

 OracleCommand command = conn.CreateCommand();
 command.CommandType = CommandType.StoredProcedure;

 command.CommandText = "TIMVW.TESTPACKAGE.GET_TESTS";
 command.Parameters.Add("P_IDS", OracleDbType.Int32, new int[] { 1, 2, 3 }, ParameterDirection.Input);
 command.Parameters["P_IDS"].CollectionType = OracleCollectionType.PLSQLAssociativeArray;
 command.Parameters.Add("P_CURSOR", OracleDbType.RefCursor, ParameterDirection.Output);

 OracleDataReader reader = command.ExecuteReader();
 while (reader.Read())
 {
  Console.WriteLine("test id: " + reader.GetDecimal(0));
 }

 Console.Write("{0}Press any key to continue…", Environment.NewLine);
 Console.ReadKey();
}

feyd | Please use[/syntax]

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
Post Reply