i just built a console application, please i need someone to tell me if its possible
How to connect a console application to a database
Collapse
X
-
Tags: None
-
It is possible! You can connect to database exactly the same way like it is done in windows application or asp.net. -
please i wouldnt mind if you show a quick step on how to do it, because i am quite new to the .net world. though i am a fast learner.Comment
-
Suppose you have a table "students" in sql server like:
Code:CREATE TABLE students (stuID int identity(1,1) primary key, sname varchar(20) not null)
Code:SqlConnection con = new SqlConnection(specify connection string here); SqlCommand cmd = new SqlCommand("INSERT INTO students VALUES(@sname)", con); Console.Write("Enter student name: "); SqlParameter sname = cmd.Parameters.Add("@sname", dbtype.varchar); sname.Value = Console.ReadLine(); cmd.ExecuteNonQuery();
Comment
Comment