‘Namespace
Imports system.data.sqlclient
Dim connNorthwind as new SqlConnection
connNorthwind.ConnectionString=“data source = (local) ; initial catalog=Northwind; integrated security=SSPI;”
‘Some of the names in the connection string also go by aliases. You can use Server instead of data source to specify your SQL Server. Instead of initial catalog, you can specify database.
The Open() Method
After you have specified the ConnectionString property of the Connection object, you must call the Open() method to establish a connection to the database.
The Close() Method
Use the Connection object’s Close() method to close an open connection.
Alternatively, you could call the Dispose() method, which also closes the connection:
ConnNorthwind.Dispose()
Imports system.data.sqlclient
Public Class Form1
System.EventArgs) Handles Button1.Click
connNorthwind.ConnectionString = "data source=(local); initial
catalog=Northwind; integrated security=SSPI;"
connNorthwind.Open()
'some code here…….
connNorthwind.close()
End Sub
End Class

No comments:
Post a Comment