Library tutorials & articles
Creating a database connection
- Introduction
- The Connection String
- Opening and Closing
Introduction
Microsoft Visual Studio .NET is a new revolution in computer programming. I
am grateful that Microsoft developed such a great IDE for us. .NET had a lot
of changes to the way we program and what we program in (especially in Visual
Basic). ADO.NET had also a substantial difference from its previous versions.
It's almost a completely new language! :)
I'll show how to create a DB Connection through either OLE or SQL in runtime
using C# as well as VB. Drag and dropping in the IDE is really easy, but there
are times when you need to do it in runtime. SQL and OLE both have their own
namespaces in the .NET Framework. They contain every single object and
method that relate to that type of connection. Of course there is the namespace
for all the General Data handling, which includes objects like the dataset.
OLE = System.Data.OleDB
SQL = System.Data.SqlClient
General Data = System.Data
Step #1: Declare the Connection Object
for OLE:
VB: Friend WithEvents OleConn as new System.Data.OleDB.OleDBConnection()
C#: internal System.Data.OleDB.OleDBConnection OleConn;
for SQL:
VB: Friend WithEvents SqlConn As New System.Data.SqlClient.SqlConnection()
C#: internal System.Data.SqlClient.SqlConnection SqlConn;
Some may wonder why I applied the WithEvents and Friend
or internal modifiers to the objects.
Reason for WithEvents:
-We can create procedures to handle the connection's events...
like the StateChanged event
Reason for internal or Friend:
-Make it available throughout the whole project
Related articles
Related discussion
-
Binary Studio | software development outsourcing Ukraine
by shane124 (4 replies)
-
Research topic in software
by reachsangeethamathew (0 replies)
-
career improvement advice
by hnasr82 (0 replies)
-
Advice on studying and preparing for interviews
by caryatid (0 replies)
-
Chart insertation in a windows form...
by pdhanik (1 replies)
Related podcasts
-
More jQuery in ASP.NET
In this episode Chris Brandsma, Rick Strahl, Dave Ward, Bertrand Le Roy, and Scott Koon conclude their discussion of Microsoft's jQuery in ASP.NET announcement1.This episode of the Alt.NET Podcast is brought to you by LLBLGen Pro, the most mature O/R mapper and code generator out there.Are ...
Events coming up
-
Nov
18
15 Minutes of Fame
Dresher, United States
This is a yearly tradition. We select 10 of the favorite speakers from monthly meetings, code camps, and hands on labs. Each one does a 15 minute talk on their favorite .NET technology. This is our 10th anniversary so we plan a gala event with special prizes and refreshments.
Thanks for taking the time to post this great little sample, complete with a working app and source code. It was very helpful to me. May you get laid constantly in college, graduate with a nice CS degree, and land a job at a hot game developer outfit where you get paid to have fun building stuff while making a ton of money.
here is my codes..please tell my the error and what else do i need to put..
Try
"Provider=Microsoft.Jet.OLEDB.4.0; Data Source=c:\App1\Your_Database_Name.mdb; Jet OLEDB:Database Password=Your_Password"
Hi..
I'm trying to connect to an access database that is protected by password. but, it's always says "the database is being opened exclusively by another program" even I don't open other application. Please help me to solve this problem
string qryStr;
OleDbConnection dbConn;
connStr = "Provider=Microsoft.Jet.OLEDB.4.0; " +
"Data Source=G:\\Backup\\Kashif\\xyzDB.mdb";
qryStr = "select content,websiteID from content";
dbConn = new OleDbConnection(connStr);
Amir
Plz reply me when i ma writing in c# using System.Data.Ado for the database connection with m.s acess then it is giving errror the type name space ado does not exist in in the class system.Data.ADO
what is reason
plz answer me
I keep getting an error when I try and create a new data connection. This is the error I'm getting.
Unable to connect to database.
It is only possible to connect to SQL Server Desktop Engine databases and Microsoft Access with this version of Visual Studio.
I can connect to Access without any problems. Is there anyway around this?
I'm using VB .net Standard with SQL Server 2000.
Thanks for any help.
Sir,
I am presently engaged in doing networking project in VB.NET and MSAcces.
I would like to know the connection string
(Provider=Microsoft.Jet.OLEDB.4.0;Data Source=.......) for connecting to a database in another machine(given its machine name) in a network while sitting in my own machine(also in the same network). I would be grateful if you help. Expecting your early reply,
Thank you
Renjini S
Please mail me at
srenjini@sify.com
It´s ok. works good
This thread is for discussions of Creating a database connection.