vb6.0中如何把EXCEL表格中的数据导入到SQL2000中 过滤重复值 10
OnErrorResumeNextCommonDialog1.FileName=""CommonDialog1.Flags=4096CommonDialog1.Filte...
On Error Resume Next
CommonDialog1.FileName = ""
CommonDialog1.Flags = 4096
CommonDialog1.Filter = "Excel文件(*.xls)|*.xls"
CommonDialog1.FilterIndex = 3
CommonDialog1.DialogTitle = "Open File(*.xls)"
CommonDialog1.Action = 1
If CommonDialog1.FileName = "" Then
MsgBox "没有选择文件", 37, "提示"
Else
Dim cn As ADODB.Connection
Dim strSQL As String
Dim lngRecsAff As Long
Set cn = New ADODB.Connection
cn.Open "driver=sql server;server=(local);uid=sa;database=student"
strSQL = "INSERT INTO scores(s_id,sch_year,c_term,c_name,c_score) select " & "s_id,sch_year,c_term,c_name,c_score FROM " & _
"OPENROWSET('Microsoft.Jet.OLEDB.4.0'," & _
"'Excel 8.0;Database=" & CommonDialog1.FileName & "',Sheet1$)"
Debug.Print strSQL
cn.Execute strSQL, lngRecsAff, adExecuteNoRecords
Debug.Print "Records affected: " & lngRecsAff
MsgBox "本次共导入" & lngRecsAff & "条记录!"
cn.Close
Set cn = Nothing
End If 展开
CommonDialog1.FileName = ""
CommonDialog1.Flags = 4096
CommonDialog1.Filter = "Excel文件(*.xls)|*.xls"
CommonDialog1.FilterIndex = 3
CommonDialog1.DialogTitle = "Open File(*.xls)"
CommonDialog1.Action = 1
If CommonDialog1.FileName = "" Then
MsgBox "没有选择文件", 37, "提示"
Else
Dim cn As ADODB.Connection
Dim strSQL As String
Dim lngRecsAff As Long
Set cn = New ADODB.Connection
cn.Open "driver=sql server;server=(local);uid=sa;database=student"
strSQL = "INSERT INTO scores(s_id,sch_year,c_term,c_name,c_score) select " & "s_id,sch_year,c_term,c_name,c_score FROM " & _
"OPENROWSET('Microsoft.Jet.OLEDB.4.0'," & _
"'Excel 8.0;Database=" & CommonDialog1.FileName & "',Sheet1$)"
Debug.Print strSQL
cn.Execute strSQL, lngRecsAff, adExecuteNoRecords
Debug.Print "Records affected: " & lngRecsAff
MsgBox "本次共导入" & lngRecsAff & "条记录!"
cn.Close
Set cn = Nothing
End If 展开
展开全部
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim con, com As String
com = TextBox1.Text
con = TextBox2.Text
SqlDataAdapter1.Fill(DataSet11, "table")
If DataSet11.Tables("table").Rows.Count = 0 Then
MsgBox("用户名或密码错误,请重新输入", vbMsgBoxSetForeground, "系统提示!!")
Else
Form2.Show()
Me.Hide()
End If
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim a As Integer
a = MsgBox("确定要退出本系统吗?", 3 + 32 + 256, "系统提示!!")
If a = 6 Then
End
End If
End Sub
End Class
你给看看我这个,运行的时候FILL函数没有效果,dataset的表里没有得到密码表的数值。我是用sqlconnection控件写得,执行select语句都没在代码里,都在控件里了,你懂得。
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim con, com As String
com = TextBox1.Text
con = TextBox2.Text
SqlDataAdapter1.Fill(DataSet11, "table")
If DataSet11.Tables("table").Rows.Count = 0 Then
MsgBox("用户名或密码错误,请重新输入", vbMsgBoxSetForeground, "系统提示!!")
Else
Form2.Show()
Me.Hide()
End If
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim a As Integer
a = MsgBox("确定要退出本系统吗?", 3 + 32 + 256, "系统提示!!")
If a = 6 Then
End
End If
End Sub
End Class
你给看看我这个,运行的时候FILL函数没有效果,dataset的表里没有得到密码表的数值。我是用sqlconnection控件写得,执行select语句都没在代码里,都在控件里了,你懂得。
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询