Current location - Training Enrollment Network - Books and materials - Our teacher asked to make a book management system with VB2005. How to connect SQL database with VB, specifically, I don't quite understand.
Our teacher asked to make a book management system with VB2005. How to connect SQL database with VB, specifically, I don't quite understand.
Module SQL module

As a public SQL connection for the new system. data.sqlclient.sqlconnection。

As a common SQL instruction for the new system. Data.sqlclient.sqlcommand (",SQL connection)

The public function connects SQL server () as the system. data.connectionstate。

attempt

SQL connection. connectionstring = " data source =(local); Initial directory = home directory; Integrated security = True User ID = sa password = "

Parameter description:

First, the data source

Server IP address

Second, the initial directory

Database name

Three. Integrated security or trusted connections

When this value is True, the current Windows account credentials will be used for authentication.

When the value is False, the user ID and password will be specified in the connection.

Recognizable values are true, false, yes, no and SSPI equivalent to true (highly recommended).

Four. User identification

Login account

Verb (abbreviation for verb) password

Login password

SQL connection. Open ()

Catch ex as an exception

MsgBox("SQL Server connection failed. " ,MsgBoxStyle。 Critical, "Connection Failed")

finally

Connect SQLServer = SQL connection. condition

End the attempt

End function

Terminal module

Create a new window and add a DataGridView 1 control to display the data.

Add the following code in the procedure to display all the data of a table in the database:

Public data table as new data table

SQL instruction. CommandText = " Select * From table name "

Data sheet. Load(SQL instruction. ExecuteReader)

DataGridView 1。 Datasource = data table.