473,396 Members | 1,748 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

How to connect a console application to a database

i just built a console application, please i need someone to tell me if its possible
Oct 5 '10 #1
3 2634
It is possible! You can connect to database exactly the same way like it is done in windows application or asp.net.
Oct 5 '10 #2
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.
Oct 6 '10 #3
Suppose you have a table "students" in sql server like:

Expand|Select|Wrap|Line Numbers
  1. CREATE TABLE students
  2. (stuID int identity(1,1) primary key,
  3. sname varchar(20) not null)
  4.  
to insert records to this table:

Expand|Select|Wrap|Line Numbers
  1. SqlConnection con = new SqlConnection(specify  connection string here);
  2.  
  3. SqlCommand cmd = new SqlCommand("INSERT INTO students VALUES(@sname)", con);
  4.  
  5. Console.Write("Enter student name: ");
  6.  
  7. SqlParameter sname = cmd.Parameters.Add("@sname", dbtype.varchar);
  8.  
  9. sname.Value = Console.ReadLine();
  10.  
  11. cmd.ExecuteNonQuery();
  12.  
  13.  
Oct 6 '10 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Chris | last post by:
Hi, Currently, I have a console application written in C# and an unmanaged legacy DLL written in VC++ 6.0. In the DLL's previous application, when an event occurs in the DLL, a windows message...
5
by: Barry Mossman | last post by:
Hi, can I detect whether my class is running within the context of a Console application, vs say a WinForm's application ? also does anyone know whether the compiler or runtime is smart enough...
2
by: Mamatha | last post by:
Hi I developed one website in ASP and i am developing desktop application in VB.Both MS-Access databases(website and desktop) are maintained on the website,then how can i connect to the remote...
1
by: gujarsachin2001 | last post by:
Hello friends, I want to connect http or https by taking url, username & password from user (if necessary )& then connect to download file from that source in console application. Can u help...
0
by: suedasszyy | last post by:
Haiiii.... i'm new for VB.net. can someone help me to solve those question? is it possible to draw a graph such as Sin graph using console application? if not, how can i draw a graph...
1
by: Claudia Fong | last post by:
Hello I'm trying to connect to a sql database using C# console application but I'm having trouble to connect.. can someone help me? // Create an empty SqlConnection object. using...
5
by: Claudia Fong | last post by:
Hi, I'm using console application to connect to a db and I managed to use the SELECT statement to display records in my DB but I also need to UPDATE some fields in my table but after I run the...
4
by: =?Utf-8?B?QWxleGFuZGVy?= | last post by:
Hi! I am new to C#. I read two C# books in the last two days which only covered the basics. And now I am on my third day. The books were really bad, because they did not cover windows applications,...
6
by: Paulers | last post by:
Hello, I am trying to manipulate a console based application from another application for example I need to launch the console application, provide it input and take the output from the console...
2
by: xinnie | last post by:
Ok, I'm totally new at CSharp. I have written some codes in Visual Studio, console application. Here shown below : using System; using System.IO; using System.Net; using System.Text; using...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.