anyone tell me a detail of database connectivity in vb.net with sql server and oracle.i already tried it on my laptop.but it shows errors.1 year back i successfully did the connectivity.but now i forgotton how it do?even i could not able to coonect ms-access with vb.it always shows error.any one tell me the basic details to advanced details step by step for this connectivity.for all 1.ms-access
2.SQL Server
3.oracle
from sheelap
saleem.mukhtiar 0 Newbie Poster
you can connect through wizrad using data set and data source data navigation from Data sub options in tool panel
.
or
through code
..
ist import the namesapces
.
for sql
import system.data.sqlclient
DATA connection
dim dt as new sqlConnection = ("data source=.; integrated security= true; database name= DATA BASE")
dt.open()
.
then desired action
SqlDataAddaptor, SqlCommand, or DataReader
.
Hope its help full for you
Edited by saleem.mukhtiar because: comments not required
poojavb 29 Junior Poster
I have done the connection but by providing modules...check if it helps u...
for ms access
Imports System.Data.OleDb Module DBConnection Public Connection As OleDbConnection = New OleDbConnection() Public Function Open_DB_Connection() As String Try Dim EntireFile As String = Application.StartupPath & "\HMS.mdb" Connection.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0.; " & "Data Source=" & EntireFile Connection.Open() Return "Success" Catch ex As Exception Debug.Print(ex.Message & "in DBConnection_Module") Return "Fail" Exit Function End Try End Function Public Function Close_DB_Connection() As String Try Connection.Close() Return "Success" Catch ex As Exception Debug.Print(ex.Message & "in DBConnection_Module") Return "Fail" Exit Function End Try End Function End Module
SQL server
Imports System.Data.SqlClient Module DBConnection Public Connection As SqlConnection = New SqlConnection() Public Function Open_DB_Connection() As String Try Connection.ConnectionString = "Server=.\SQLEXPRESS;" & _ "Database=HMS;Trusted_Connection=True" Connection.Open() Return "Success" Catch ex As Exception Debug.Print(ex.Message & "in DBConnection_Module") Return "Fail" Exit Function End Try End Function Public Function Close_DB_Connection() As String Try Connection.Close() Return "Success" Catch ex As Exception Debug.Print(ex.Message & "in DBConnection_Module") Return "Fail" Exit Function End Try End Function End Module
I am not sure for Oracle...
Create the module once and when we need to call the open connection just call the function and same for close connection
Dim Open_DB_Con As String
Open_DB_Con = Open_DB_Connection()
Dim Close_DB_Con As String
Close_DB_Con = Close_DB_Connection()
I know its too long but still worthy....
u can also give success msg if the connection suceeds and also a failure message if it fails after the function is called....
like
If Open_DB_Con = "Success" Then
Debug.Print("Database connection sucessfull in frmAppointment Appointment Date Change Event")
ElseIf Open_DB_Con = "Fail" Then
Debug.Print("Could not establish DataBase connection! ")
End If
If Close_DB_Con = "Success" Then
Debug.Print("Database connection closed in frmAppointment Validate Registration Event")
ElseIf Close_DB_Con = "Fail" Then
Debug.Print("Could not close DataBase connection! ")
End If
Note: Creating module helps in repeating the same connection string again and again...just calling the function helps....
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.