主题:文件导入导出问题 内附代码 请高手修改
文件导出代码:
Sub DCSJ()
If myCon.State = ConnectionState.Closed Then
myCon.Open()
End If
Try
Dim sFilename As String
With Me.SaveFileDialog1
.Title = "保存文件"
.CheckFileExists = False
.CheckPathExists = False
.CreatePrompt = True
.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*"
.ShowDialog()
sFilename = .FileName
End With
If sFilename = "" Then
MessageBox.Show("请输入您要保存的文件名。", "错误信息", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
Exit Sub
Else
Dim myStreamWriter As StreamWriter
myStreamWriter = File.CreateText(sFilename)
Dim myOutput As String
If myCon.State = ConnectionState.Closed Then
myCon.Open()
End If
Dim MyCmd As New OleDb.OleDbCommand("SELECT * FROM PACKLIST ORDER BY ID", myCon)
MyDa.SelectCommand = MyCmd
myDataSet.Clear()
MyDa.Fill(myDataSet, "table")
If myDataSet.Tables(0).Rows.Count > 0 Then
Dim row As DataRow
For Each row In myDataSet.Tables(0).Rows()
myStreamWriter.WriteLine(row!CTN_NO & "")
myStreamWriter.WriteLine(row!MAT_NM & "")
myStreamWriter.WriteLine(row!MAT_SPC & "")
myStreamWriter.WriteLine(row!EUNIT & "")
myStreamWriter.WriteLine(row!ENT_QNT & "")
myStreamWriter.WriteLine(row!DEL_QNT & "")
myStreamWriter.WriteLine(row!PK_QNT & "")
myStreamWriter.WriteLine(row!SPK_QNT & "")
myStreamWriter.WriteLine(row!N_WT & "")
myStreamWriter.WriteLine(row!G_WT & "")
myStreamWriter.WriteLine(row!ID & "")
Next
myStreamWriter.Flush()
myStreamWriter.Close()
End If
End If
Catch ex As Exception
MessageBox.Show(Err.Description)
End Try
End Sub
Sub DCSJ()
If myCon.State = ConnectionState.Closed Then
myCon.Open()
End If
Try
Dim sFilename As String
With Me.SaveFileDialog1
.Title = "保存文件"
.CheckFileExists = False
.CheckPathExists = False
.CreatePrompt = True
.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*"
.ShowDialog()
sFilename = .FileName
End With
If sFilename = "" Then
MessageBox.Show("请输入您要保存的文件名。", "错误信息", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
Exit Sub
Else
Dim myStreamWriter As StreamWriter
myStreamWriter = File.CreateText(sFilename)
Dim myOutput As String
If myCon.State = ConnectionState.Closed Then
myCon.Open()
End If
Dim MyCmd As New OleDb.OleDbCommand("SELECT * FROM PACKLIST ORDER BY ID", myCon)
MyDa.SelectCommand = MyCmd
myDataSet.Clear()
MyDa.Fill(myDataSet, "table")
If myDataSet.Tables(0).Rows.Count > 0 Then
Dim row As DataRow
For Each row In myDataSet.Tables(0).Rows()
myStreamWriter.WriteLine(row!CTN_NO & "")
myStreamWriter.WriteLine(row!MAT_NM & "")
myStreamWriter.WriteLine(row!MAT_SPC & "")
myStreamWriter.WriteLine(row!EUNIT & "")
myStreamWriter.WriteLine(row!ENT_QNT & "")
myStreamWriter.WriteLine(row!DEL_QNT & "")
myStreamWriter.WriteLine(row!PK_QNT & "")
myStreamWriter.WriteLine(row!SPK_QNT & "")
myStreamWriter.WriteLine(row!N_WT & "")
myStreamWriter.WriteLine(row!G_WT & "")
myStreamWriter.WriteLine(row!ID & "")
Next
myStreamWriter.Flush()
myStreamWriter.Close()
End If
End If
Catch ex As Exception
MessageBox.Show(Err.Description)
End Try
End Sub