vb excel导入数据库怎么做? 200
现有数据库名称abc.mdb,密码123,表名dingdan字段:订单号,下单时间,买家,邮箱,收件人,地址,备注要求将excel内的数据导入到数据库中,以订单号作为比较...
现有数据库名称abc.mdb,密码123,表名dingdan
字段:订单号,下单时间,买家,邮箱,收件人,地址,备注
要求将excel内的数据导入到数据库中,以订单号作为比较数据,若发现又重复的,就不导入,并最后提示所有重复的订单号。
实在不会做这个,请大侠帮忙,200悬赏奉上,谢谢! 展开
字段:订单号,下单时间,买家,邮箱,收件人,地址,备注
要求将excel内的数据导入到数据库中,以订单号作为比较数据,若发现又重复的,就不导入,并最后提示所有重复的订单号。
实在不会做这个,请大侠帮忙,200悬赏奉上,谢谢! 展开
展开全部
提供一段用于操作Excel表格的代码参考:
Private Sub openExcel()
Adodc1.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Persist Security Info=False;Data Source=" _
& fileName & ";Extended Properties='Excel 8.0;HDR=Yes'"
Adodc1.RecordSource = "select * from [Sheet1]"
Adodc1.Refresh
Set DataGrid1.DataSource = Adodc1
Set DataGrid2.DataSource = Adodc1
zsl = Adodc1.Recordset.RecordCount
ReDim sinYH(zsl)
Adodc1.Recordset.MoveFirst
ReDim sinXH(19, 1 To zsl)
For j = 1 To zsl
sinYH(j) = Adodc1.Recordset("M000")
For i = 1 To 6
sinXH(i, j) = Adodc1.Recordset(i + 1)
Next i
Adodc1.Recordset.MoveNext
Next
Text1 = sinYH(zsl)
Text2 = sinXH(1, zsl)
Timer1.Enabled = True
End Sub
追问
能按我的想法帮我编一个代码吗?你发的我看不懂。
追答
能提供代码参考已经不错了,编一个软件是一种脑力劳动。
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
Private Sub test()
Dim mydatayj As String, mytableyj As String, sqlyj As String
Dim cnnyj As ADODB.Connection
Dim rsyj As ADODB.Recordset
mydatayj = strDatayj
mytableyj = strLoanTable
Set cnnyj = New ADODB.Connection
cnnyj.Provider = strConnyj
cnnyj.Open mydatayj
Set rsyj = New ADODB.Recordset
sqlyj = "insert into " & mytableyj & " (Recorder,CallTime,Insd,Polno,Icno,QuesType,Email,Detail,Address,Tel,DealEnd,bak) values('" & Recorder.Text & "','" & CallTime.Text & "','" & Insd.Text & "','" & Polno.Text & "','" & QuesType.Text & "','" & Icno.Text & "','" & Email.Text & "','" & Detail.Text & "','" & Address.Text & "','" & Tel.Text & "','" & DealEnd.Caption & "','" & bak.Text & "')"
cnnyj.Execute sqlyj
cnnyj.Close
Set rsyj = Nothing
Set cnnyj = Nothing
End Sub
'=====================================
Function RunSql(sql As String)
Dim cnn As Object
Set cnn = CreateObject("adodb.connection")
Set RunSql = CreateObject("adodb.recordset")
cnn.Open "Provider=sqloledb;Server=服务器名称或IP地址;Database=数据库名称;Uid=用户登录名;Pwd=密码;"
RunSql.Open sql, cnn, 1, 3
Set cnn = Nothing
End Function
Sub UpdateSQL()
Dim arr, sql$
arr = ActiveSheet.UsedRange
For i = 2 To UBound(arr, 1)
sql = " update Table set "
For j = 1 To UBound(arr, 2)
sql = sql & arr(1, j) & "='" & arr(i, j) & "',"
Next
sql = Left(sql, Len(sql) - 1) & " where 指标编码='" & arr(i, 1) & "'"
MsgBox sql
RunSql sql
Next
MsgBox "更新完毕!"
End Sub
看看有没有帮助
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
提供一段用于操作Excel表格的代码参考:
Private Sub openExcel()
Adodc1.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Persist Security Info=False;Data Source=" _
& fileName & ";Extended Properties='Excel 8.0;HDR=Yes'"
Adodc1.RecordSource = "select * from [Sheet1]"
Adodc1.Refresh
Set DataGrid1.DataSource = Adodc1
Set DataGrid2.DataSource = Adodc1
zsl = Adodc1.Recordset.RecordCount
ReDim sinYH(zsl)
Adodc1.Recordset.MoveFirst
ReDim sinXH(19, 1 To zsl)
For j = 1 To zsl
sinYH(j) = Adodc1.Recordset("M000")
For i = 1 To 6
sinXH(i, j) = Adodc1.Recordset(i + 1)
Next i
Adodc1.Recordset.MoveNext
Next
Text1 = sinYH(zsl)
Text2 = sinXH(1, zsl)
Timer1.Enabled = True
End Sub
Private Sub openExcel()
Adodc1.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Persist Security Info=False;Data Source=" _
& fileName & ";Extended Properties='Excel 8.0;HDR=Yes'"
Adodc1.RecordSource = "select * from [Sheet1]"
Adodc1.Refresh
Set DataGrid1.DataSource = Adodc1
Set DataGrid2.DataSource = Adodc1
zsl = Adodc1.Recordset.RecordCount
ReDim sinYH(zsl)
Adodc1.Recordset.MoveFirst
ReDim sinXH(19, 1 To zsl)
For j = 1 To zsl
sinYH(j) = Adodc1.Recordset("M000")
For i = 1 To 6
sinXH(i, j) = Adodc1.Recordset(i + 1)
Next i
Adodc1.Recordset.MoveNext
Next
Text1 = sinYH(zsl)
Text2 = sinXH(1, zsl)
Timer1.Enabled = True
End Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2017-06-25 · 百度知道合伙人官方认证企业
育知同创教育
1【专注:Python+人工智能|Java大数据|HTML5培训】 2【免费提供名师直播课堂、公开课及视频教程】 3【地址:北京市昌平区三旗百汇物美大卖场2层,微信公众号:yuzhitc】
向TA提问
关注
展开全部
vb导入excel数据?需要通过编程实现
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询