永发信息网

怎样把VB中TEXT的内容录入SQL

答案:3  悬赏:60  手机版
解决时间 2021-05-07 08:09
  • 提问者网友:喧嚣尘世
  • 2021-05-07 02:13

在一个VB的窗体中有TEXT1,TEXT2,...........TEXT10。十个要输入的窗口,

怎样把这十个TEXT窗口的数据通过“保存按键”正确的录入到ACCESS或是SQL中。

注:TEXT1.....TEXT10在数据库中的属性都是文本,大小50

要求:

1:TEXT1的数据录入到ACCESS中的A1中。TEXT2的数据录入到ACCESS的A2中..........一直到TEXT10.

2:在程序录入的语句中有注解。

最佳答案
  • 五星知识达人网友:神鬼未生
  • 2021-05-07 03:19

Private Sub Command1_Click()

Dim conn As ADODB.Connection
Dim cnn As ADODB.Recordset
Dim strAppPath As String
strAppPath = App.Path
If Right(strAppPath, 1) <> "\" Then
strAppPath = strAppPath & "\"
End If
strAppPath = strAppPath & "数据库名.mdb"
Dim str As String
str = "DRIVER=Microsoft Access Driver (*.mdb);DBQ=" & strAppPath & ""
conn.Open str
cnn.Open "select * from 表名", conn, adOpenKeyset, adLockPessimistic
cnn.AddNew
For i = 1 To 10
Text(i).Text = cnn!A(i)
Next
cnn.Update
MsgBox "保存成功!"


End Sub

全部回答
  • 1楼网友:鸽屿
  • 2021-05-07 04:47

引用ADO2.6,一个按钮,10个TEXT复制一下代码即可

Private Sub form_load()

Dim conn As ADODB.Connection Dim strAppPath As String strAppPath = App.Path '获取程序所在根目录 If Right(strAppPath, 1) <> "\" Then strAppPath = strAppPath & "\" End If strAppPath = strAppPath & "数据库名.mdb" Dim str As String str = "DRIVER=Microsoft Access Driver (*.mdb);DBQ=" & strAppPath & "" conn.Open str '链接ACCESS数据库,打开

end sub

private command1_click()

dim str as string

DIM rs as adodb.recordset

set rs=new adodb.recordset

str= "insert into 表名('A1','A2','A3','A4','A5','A6','A7','A8','A9','A10'') VALUE("& TEXT1.TEXT &","& TEXT2.TEXT &","& TEXT3.TEXT &","& TEXT4.TEXT &","& TEXT5.TEXT &","& TEXT6.TEXT &","& TEXT7.TEXT &","& TEXT8.TEXT &","& TEXT9.TEXT &","& TEXT10.TEXT &")“ '插入数据的SQL语句,要放在一行使用,如果换行在行尾加 " & _

rs.open str,conn,adopenstatic '执行插入操作

msgbox "保存成功!"

End Sub

  • 2楼网友:夜余生
  • 2021-05-07 03:31

dim x

x=array(txt1,txt2..........txt10)

for i=1 to 10

cn.exec"insert into " & choose(1,a1,a2,a3,a4...a10) & "(" & choose(i,a1.feilds.............) & ")values(" & x(i-1).text &")"

next i

我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯