Page 1 of 1
SQL guide for a C# console program
Posted: Wed Nov 14, 2007 1:33 am
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

simple code.
This is also my "Do to learn" project

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!!!!
Well does one of you guys know an easy to follow guide for using sql in a console program?
Posted: Mon Nov 26, 2007 12:31 pm
by timvw
feyd | Please use 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
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]