tags:

views:

340

answers:

2

I'm not very familiar with the console application but i think its kind a interesting subject to learned. I searched for tutorials and references related to connecting MySQL database in console but no luck. So i just try and error. Please correct me I'm wrong..

I had an application where when user run the program, it'll store values to database. In the Form Application, it runs well(no doubt). Now with the same approach, i want it to be run it in the console application. So, I create new project in console and just copy, do some editing on the codes and put in Main. Luckily, the code running well.

My concerns are, is it what i'm doing is write? the command for the form can be used in console? What are differences between this two? is this the better approached?

Any advice and references are very helpful.

+2  A: 

There's very little difference between console apps and WinForms apps in terms of the pieces of code which actually interact with the database.

One significant difference between them in the surrounding code is that you'd usually use a different thread to perform the database access in a WinForms app, to avoid blocking the UI thread. If you're just writing the data out to a console, there's no need for that.

Jon Skeet
Ok, thx all...what I'm understand now, there are no much different in code but only in term of UI. On what u said, "There's very little difference between console apps and WinForms apps in terms of the pieces of code which actually interact with the database." Can u show me some example codes on How and What is the best solution of it in console application.
(p/s:Example code in Winform.I did tried copy,paste,n run the code in console n it run's well too)//create connection System.Data.SqlClient.SqlConnection con;DataSet ds1;System.Data.SqlClient.SqlDataAdapter da;//in FormLoad() open connectioncon = new System.Data.SqlClient.SqlConnection();ds1 = new DataSet();con.ConnectionString = "<dbase path>con.Open();//insert commandString sInsert = "INSERT INTO tblOutbox (ip_addr, message,date)" + VALUES( 'value1', 'value2', 'date')";da = new System.Data.SqlClient.SqlDataAdapter(sInsert, con);da.Fill(ds1, "tblOutbox");//close con
+1  A: 

Console applications are typically designed without a graphical user interface. A console application is run from the command line with input and output information being exchanged between to and from the console window, this makes the console application a great way to learn new programming technique without having to be concerned with the user interface.

adatapost