'(测试OK,添加"Table1"数据表,包含4个字段):
Set
NewTable
=
CurrentDb.CreateTableDef("Table1")
With
NewTable
.Fields.Append
.CreateField("字段1",
dbText)
.Fields.Append
.CreateField("字段2",
dbText)
.Fields.Append
.CreateField("字段3",
dbText)
.Fields.Append
.CreateField("字段4",
dbText)
End
With
CurrentDb.TableDefs.Append
NewTable
记住:在data3.databasename
=
app.path
+
"\tushu1.mdb"
'这是设置data3控件数据库的路径
data3.recordsource
=
"denglu"
'这个是选择数据库中的表
后面不要忘记刷新;
data3.refresh
另外,你既然用了
text1.text
=
data3.recordset.fields("用户名")
text2.text
=
data3.recordset.fields("密码")
text3.text
=
data3.recordset.fields("密码")
那前面的三行是多余的了
text1.datasource
=
"data3"
'这是个文本框控件设置数据源
text2.datasource
=
"data3"
text3.datasource
=
"data3"
要么这样:
text1.datasource
=
"data3"
'这是个文本框控件设置数据源
text2.datasource
=
"data3"
text3.datasource
=
"data3"
text1.datafield
=
"用户名"
text2.datafield
=
"密码"
text3.datafield
=
"密码"
在Excle中录入好数据以后,可能会需要用VB进行读取Excle数据,具体该如何读取数据呢?下面是我带来的关于vb读取excel数据的教程,希望阅读过后对你有所启发!
vb读取excel数据的教程:
Private Sub Form_Load()
Text1.Text = App.Path &"\123.xls"
Text2.Text = App.Path &"\123.mdb"
Text3.Text = "sheet1"
Text4.Text = "sheet1"
Data1.DatabaseName = App.Path &"\123.mdb"
End Sub
Private Sub Command1_Click()
Dim db As Database
Dim sheet As String, excelpath As String, AccessPath As String, AccessTable As String
AccessPath = Text2.Text '数据库路径
excelpath = Text1.Text '电子表格路经
AccessTable = Text4.Text '数据库内表格
sheet = Text3.Text '电子表格内工作表
Set db = OpenDatabase(excelpath, True, False, " Excel 5.0") '打开电子表格文件
SQL = ("Select * into [database=" &AccessPath &"]." &AccessTable &" FROM [" &sheet &"$]")
db.Execute (SQL) '将电子表格导入数据库
Data1.RecordSource = "sheet1"
Data1.Refresh
DBGrid1.Refresh '显示电子表格导入到数据库的数据
End Sub
上面的是把EXCEL读取到数据库中,你做点修改就行了.一个Data控件.
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)