-
This program of the landlord is written into a notepad. If you want to write data to the access database.
The first step is to reference the database connection driver.
In"Engineering"--"References"and select it"microsoft activex date objects library"
Then add the following to the window box:
dim conn as new
dim rs as new
dim sql$
function openconn()
provider=; data source=" & "data" 'This is the relative path of the database.
end function
function closeconn()
end function
private sub command1_click()call openconn
select * from [Table 1].", conn, 1, 3rs("Name") =
rs("Scores") =
call closeconn
msgbox "Added data successfully! "
end sub
-
The following can be used only if the library reference and database connection are correct:
There are two ways, one is to use SQL, and the other is to use ADO1 to add data
insert into the table name (field 1, field 2, field 3) values (value 01, value 02, value 03).
For example:"insert into emptable(name,age,duty,salary) values('Wang Ming',35,'Director of Foreign Trade',12500)"
2. Use the ADO method:
ADO is more complicated, so let's give you a complete example:
dim strsqlfitjc as stringstrsqlfitjc = "select from the table"
set rsfitjc = new 'defines an ADO connection to the database.
strsqlfitjc, cn, adopenkeyset, adlockoptimistic 'open the connection.
Add a record.
Fitting number") = "style" 'to assign a value to each field. update 'Stores a new record of the assignment.
close closes the connection.
end with
-
This program of the landlord is written into a notepad. If you want to write data to the access database.
The first step is to reference the database connection driver.
In"Engineering"References"and select it"microsoft activex date objects library"
Then add the following to the window box:
dim conn as new
dim rs as new
dim sql$
function openconn()
provider=; data source="& Arguments" 'This is the relative path of the database wild.
end function
function closeconn()
end function
private sub command1_click()call openconn
select * from [Table 1].",conn, 1, 3rs("Name")
rs("Scores")
call closeconn
msgbox "Added data successfully! "
end sub
Is it okay to sing the round skin like this?
-
set db = opendatabase( &", false, false, "shouting and dispersing; pwd=7994") database user, password 7994 is required to open it
set rs = "kscj"The name of the access table is kscjset rs="select * from kscj where [exam number]='userkh & query the data of an exam number.
if > 0 then 'There are already results.
userhs = rs(0)
userkh Zheng = rs(1).
userxzf = rs(4)
if userzf > userxzf then 'The higher score is the one that prevails.
set rs = "kscj")
userhs - 1
RS(4) = userzf'Write the total score.
end if
endif
-
Upstairs correct solution, you can also use the ADODC control.
dim a new
e.g. cn) database connection character.
SQL statement) is an insert statement such as insert or an update statement of the update class, you can overwrite or add access data.
-
First of all, add ADODC space in the form, set up the connection database, and then bind it with each text control, and then write**, you can check it in the morning, and look at some** on the line, it's the same!
-
"User's name")
User password")
User Permissions") 1
adodc1 is the name of the control, and this goes without saying. And the adodc1 control has been set up such as a connection string, which can be set in the properties of the control.
The first sentence adds a new item to the recordset.
The next few sentences write data to the corresponding field.
The last sentence updates the recordset.
-
1. First of all, in the form load() event of the form (or in the programming), you need to set the database and data table connected to adodC1.
For example, adodc1 connects to the access database.
The name of the database is: stored in d:
The name of the data table is T101
with adodc1
cursortype = adopendynamic
connectionstring = "provider=;data source=
d:\;persist security info=false"
recordsource = "select * from t101"
refresh
end with
2. Add new data records.
Name")=trim(text1)
Pay attention to whether the fields in the data table except "Name" are limited or cannot be empty.
Otherwise, an error will be reported when updating!
To set the .cursortype = adopendynamic Otherwise, the latest data will not be seen in the data source adodc1 after the data is updated.
-
If you're using VS, DataGrid is handy.
-
After connecting to the database, you can query, add, modify, and delete data to add'Add an empty record.
Item number") =
The title of the product") =
Merchandise**") = val(
Save the data.
-
There are two ways, one is SQL and the other is ADO
1. Add data with SQL
insert into the table name (Field 1, Field 2, Field 3).
values (value 01, value 02, value 03).
For example:"insert into emptable(name,age,duty,salary) values('Wang Ming',35,'Director of Foreign Trade',12500)"
2. Use the ADO method:
ADO is more complicated, so let's give you a complete example:
dim strsqlfitjc as string
strsqlfitjc = "select from the table"
set rsfitjc = new 'defines an ADO connection to the database.
strsqlfitjc, cn, adopenkeyset, adlockoptimistic 'open the connection.
Add a record.
Fitting number") = "style" 'to assign a value to each field.
update 'Stores a new record of the assignment.
close closes the connection.
end with
My habit is to use the shutdown command in the shell.
a=shell("shutdown -f -s -t 0"relationship. >>>More
I think it's time to buy a VB book. Break the bank!
dim xlbook as 'Workbooks.
dim xlsheet as 'Worksheet. >>>More
The operating system of Android mobile phones is similar, taking Huawei mobile phones as an example, you can try the following screenshot methods: >>>More
There is nothing wrong with learning from VB first, many people think that VB is not good, that is, they don't study very seriously, they think VB is simple and abandon it. You think VB has been around for that long, and there must be a reason for it. No matter what programming language it is, it is much simpler, as long as you learn one thing, it will be much easier to learn the others. >>>More