C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Reviews   Communities   Interview   Jobs   Projects   Training   Your Ad Here    
Silverlight Games | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Polls | Revenue Sharing | Lobby | Gift Shop |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...






Resources » Articles » .NET Framework »

DataBase Connectivity and the Handling


Posted Date: 21 Sep 2007    Resource Type: Articles    Category: .NET Framework
Author: Nivas TMember Level: Gold    
Rating: 1 out of 5Points: 10



Introduction


ADO.NET provides an object oriented paradigm for database access. In the code, the objects are instantiated from class definitions. The classes are grouped into containers called namespaces. It’s a convenience, not a requirement to create namespace references.

The Namespaces
System.Data.SqlClient
System.Data.OleDb
System.Data.OracleClient


INSERT, UPDATE and DELETE



Now we using namepaces and make connection with database through the connection string

Connection string has server, database, user id and password

Dim myConnectionString As String

myConnectionString = "Database=netpub;server=192.168.1.28;user id=root; pwd="

Dim myConnection As New SqlConnection(myConnectionString)


Hear the SqlConnection is used to make a connection with the particuler database


Make a Query to pass through connection

Dim myInsertQuery As String = "INSERT INTO user ( username, pwd, rights)
Values('test', 'test', 1)"

Dim myCommand As New SqlCommand(myInsertQuery)
myCommand.Connection = myConnection


Hear The SqlCommand is used pass the query through the SqlConnection

myConnection.Open()
myCommand.ExecuteNonQuery()
myCommand.Connection.Close()



SELECT



Make a connection and pass the Query

Dim myConnection As New SqlConnection(myConnectionString)
Dim mySelectQuery As String = "SELECT * from file where
file_id not in(select file_id from sample where status='0')"
Dim myCommand As New SqlCommand(mySelectQuery, myConnection)
myConnection.Open()


We should use DataReader to retrieve data, its gets the copy of database as readonly format

Dim myReader As SqlDataReader

now we make connection between SqlCommand and SqlDataReader Through ExecuteReader command

myReader = myCommand.ExecuteReader()

While myReader.Read()
MsgBox(myReader.GetValue(1))
End While


The Read() function is used to fetch the data from DataReader, and GetValue() class used to fetch the exact field from the Database using 0,1,2.....

myReader.Close()
myConnection.Close()


Summary



This Article may useful to Indent to performing the .Net DataBase




Responses

Author: Puja Sharma    24 Sep 2008Member Level: Gold   Points : 2
Hi Nivas,

Very useful article.
Each aspectof database connectivity is described very clearly.

Varun


Feedbacks      
Popular Tags   What are tags ?   Search Tags  
Sign In to add tags.
DataBase Connectivity and the Handling  .  

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: String and StringBuilder - A Common Mistake
Previous Resource: KeyBoard Shortcuts in Windows SharePoint Services 3.0
Return to Discussion Resource Index
Post New Resource
Category: .NET Framework


Post resources and earn money!
 
Related Resources



dotNet Slackers

About Us    Contact Us    Privacy Policy    Terms Of Use