VB2008里怎么把输入框里的输入内容加载到数据库里,然后存取以后提出来用?

2024-12-15 21:15:50
推荐回答(1个)
回答1:

楼主多看看sql语言。
我这儿有个范例:
Private Conn As New ADODB.Connection
Private Recordset As New ADODB.Recordset
Private Sub Command1_Click() '增加记录
Dim sql As String
Set Recordset = Nothing
sql = "select * from liuyan" 'SQL查询语句
Recordset.Open sql, Conn, 1, 3
Recordset.AddNew
Recordset("姓名") = Text1.Text '数据读写操作
Recordset("性别") = Text2.Text '数据读写操作
Recordset("年龄") = Text3.Text '数据读写操作
Recordset("权限") = Text4.Text '数据读写操作
Recordset("时间") = Text5.Text '数据读写操作
Recordset("内容") = Text6.Text '数据读写操作
Recordset.Update
Call Command3_Click '刷新
Recordset.Close
End Sub
Private Sub Command3_Click() '显示liuyan表中内容
Dim sql As String, tex As String
Set Recordset = Nothing
sql = "select * from liuyan" 'SQL查询语句
Recordset.Open sql, Conn, 1, 3
Do While Not Recordset.EOF
For i = 1 To Recordset.Fields.Count - 1
If i = Recordset.Fields.Count - 1 Then
tex = tex & Recordset.Fields(i).Name & ":" & Recordset.Fields(i).Value & vbNewLine
Else
tex = tex & Recordset.Fields(i).Name & ":" & Recordset.Fields(i).Value & Space(15 - Len(Recordset.Fields(i).Value))
End If '输出jsb表中各字段
Next i
Recordset.MoveNext
Loop
'Print Recordset.Fields(2).Type
Text7.Text = tex
End Sub
Private Sub Form_Load()
Conn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=G:\实验平台\数据库\留言板.mdb"
End Sub