代码如下
Public conn As ADODB.Connection
Public rs As ADODB.Recordset
==============================
Private Sub Command1_Click()
Dim mypath, mystr As String
Dim mypos As Integer
Dim SQL As String
With cd1
.FilterIndex = 3
.ShowSave
On Err GoTo err5
mystr = StrReverse(.FileName)
'Debug.Print mystr
mypos = InStr(mystr, "\")
'Debug.Print mypos
mypath = StrReverse(Mid(mystr, mypos))
'Debug.Print mypath
mystr = StrReverse(Left(mystr, mypos - 1))
'Debug.Print mystr
SQL = "select * into [excel 8.0;database=" & .FileName & "].sheet1 from class_info"
.DefaultExt = "*.XLS"
End With
If rs.State = 1 Then
rs.Close
End Iferr5:
If Err.Number = 5 Then
MsgBox ("没有选择文件")
End If
On Error Resume Next
End Sub
===========================
Private Sub Command2_Click()
Unload Me
End Sub
===========================
Private Sub Form_Load()Dim SQL As String
Dim connstring As String
connstring = "provider=sqloledb.1;persist security info=false;user id=sa;password=;Initial Catalog=student;Data Source=ybyb"
Set conn = New ADODB.Connection
conn.CursorLocation = adUseClient '加客户端游标
conn.Open connstring
Set rs = New ADODB.Recordset
rs.Open "select * from class_info", conn, adOpenStatic, adLockOptimistic
Set DataGrid1.DataSource = rs
With cd1
.Filter = "FoxBase/FoxPro (*.DBF)|*.DBF|Access 8.0(*.MDB)|*.MDB|Excel 8.0(*.XLS)|*.XLS|Paradox 4.x(*.DB)|*.DB"
.DialogTitle = "导出文件为"
.CancelError = False
End WithEnd Sub
为什么在通用对话框选择文件后,文件里没数据啊
谁有报盘的例子施舍一个吧@^@!
Public conn As ADODB.Connection
Public rs As ADODB.Recordset
==============================
Private Sub Command1_Click()
Dim mypath, mystr As String
Dim mypos As Integer
Dim SQL As String
With cd1
.FilterIndex = 3
.ShowSave
On Err GoTo err5
mystr = StrReverse(.FileName)
'Debug.Print mystr
mypos = InStr(mystr, "\")
'Debug.Print mypos
mypath = StrReverse(Mid(mystr, mypos))
'Debug.Print mypath
mystr = StrReverse(Left(mystr, mypos - 1))
'Debug.Print mystr
SQL = "select * into [excel 8.0;database=" & .FileName & "].sheet1 from class_info"
.DefaultExt = "*.XLS"
End With
If rs.State = 1 Then
rs.Close
End Iferr5:
If Err.Number = 5 Then
MsgBox ("没有选择文件")
End If
On Error Resume Next
End Sub
===========================
Private Sub Command2_Click()
Unload Me
End Sub
===========================
Private Sub Form_Load()Dim SQL As String
Dim connstring As String
connstring = "provider=sqloledb.1;persist security info=false;user id=sa;password=;Initial Catalog=student;Data Source=ybyb"
Set conn = New ADODB.Connection
conn.CursorLocation = adUseClient '加客户端游标
conn.Open connstring
Set rs = New ADODB.Recordset
rs.Open "select * from class_info", conn, adOpenStatic, adLockOptimistic
Set DataGrid1.DataSource = rs
With cd1
.Filter = "FoxBase/FoxPro (*.DBF)|*.DBF|Access 8.0(*.MDB)|*.MDB|Excel 8.0(*.XLS)|*.XLS|Paradox 4.x(*.DB)|*.DB"
.DialogTitle = "导出文件为"
.CancelError = False
End WithEnd Sub
为什么在通用对话框选择文件后,文件里没数据啊
谁有报盘的例子施舍一个吧@^@!
cd1,是个通用对话框,剩下没用什么
SQL = "select * into [excel 8.0;database=" & .FileName & "].sheet1 from class_info"
Conn.Execute SQL