The average database system programming tutorial is created when programming, and generates user data sources, system data sources, and file data, in the system, connects to the database through data sources in an integrated development environment. So, how to program it without a data source. Generate the database to be manipulated and a table? (, Such as: After the application is installed, the corresponding database is generated when the first starts. Method: Specify the legal username and password of the DBMS in the connection string of the application's ADO object, and specify the database driver and the target host. Such as: Connecting to this unit's SQL Server assumes that the username is empty. The connection string is: conn_str = "UID = sa; pwd =; driver = {SQL Server}; server = (local)" Then, the connected database can perform the corresponding operation.
Below is my original code (VB) of my analog medical system (VB): Public Sub generate_db () determines whether there is an application database file DIM DB_FILE AS STRINGDB_FILE = DIR in the application's directory, DIR (app.path "/ test .mdf ")
If DB_FILE = "" defines the connection string DIM conn_str as stringconn_str = "uid = sa; pwd =; dataBase = Master; driver = {sql server}; server = (local)"
'Object declaration to be used Dim conn As New ADODB.ConnectionDim cmd As New ADODB.CommandDim rs As New ADODB.Recordset' connected to the data source conn.Open conn_str 'create a query command cmd.CommandText = "create database test on primary (name = TEST, FILENAME = '"& app.path " /test.mdf "&", size = 5MB, MaxSize = 10MB, FileGrowth = 20%) log on (name = test_log, filename =' "& app.path "/TEST_LOG.LDF" & "', size = 2MB, MaxSize = 4MB, fileGrowth = 20%"' Execute Command (to generate a database) Conn.execute cmd.comMandtext, default, -1 'Generate database needs to be used Table cmd.commandtext = "Create Table Test. [DBO]. [DB_USER] ([User Name] [VARCHAR] (20) Collate Chinese_PRC_CI_AS Not Null, [Password] [VARCHAR] (20) Collate Chinese_PRC_CI_AS NOT NULL, [Permissions ] [varchar] (20) Collate chinese_prc_ci_as not null, [Registration Date] [VARCHAR] [VARCHAR] [VARCHAR] [20) CONN.Execute cmd.commandtext, default, -1 'gives a root user cmd.comMandText = "Insert INTO TEST. [Dbo] .db_user value ('root', 'root', 'administrator', 'original user') "Conn.execute cmd.commandtext, default, -1
Elsemsgbox "The current database file status is in good condition!", Vbokonly vbinformation, "Tips" end ifend sub 2004 October 4