Home > Net >  For help! Vb.net data export format CVS
For help! Vb.net data export format CVS

Time:09-20

Click the button to get the data in the datagridview exported to CSV file formats, but with SQL directly after export export CSV file is not the same as how to solve?
Statements for
 
Private Sub data export _Click (DGV As Object, As EventArgs e) Handles data export. Click
Dim SFD As New SaveFileDialog
SFD. Filter="CSV files files (*. CSV) | *. CSV"
'the SFD. The Filter="Excel file (*. XLS) | *. XLS | all files (*. *) | *. *"
Moban="template"
SFD. FileName=RadioButton1. Text & amp; Moban
SFD. FilterIndex=0
SFD. Title="save to CSV (comma separated) file"
SFD. InitialDirectory="F: \ flu upload "
SFD. RestoreDirectory=True
SFD. CreatePrompt=True


If SFD. ShowDialog=DialogResult. OK Then
Dim the fs As New IO. FileStream (SFD) FileName, IO. FileMode. Create)
Dim sw As New IO. StreamWriter (Unicode), fs System. Text. Encoding.
Dim the title As String=""
Dim As Integer I
'write a column header

For I=0 To DataGridView3. ColumnCount - 1
Title=DataGridView3. Columns (I). The HeaderText
Sw. Write (CRH (34))
Sw. Write (title)
Sw. Write (CRH (34))
Sw. Write (", ")
If I & lt;> Then DataGridView3. ColumnCount - 1
End the If

Next
Sw. WriteLine (" ")
Dim x As Integer
Dim y As Integer
For x=0 To DataGridView3. RowCount - 1
For y=0 To DataGridView3. ColumnCount - 1
If DataGridView3. Rows (x) Cells (y). The Value Is DBNull. Value Then
Sw. Write (" ")
The Else
Sw. Write (CRH (34))
Sw. Write (DataGridView3. Rows (x) Cells (y) Value)
Sw. Write (CRH (34))
Sw. Write (", ")
End the If
If y & lt;> Then DataGridView3. ColumnCount - 1
End the If
Next
'DataGridView3. Columns (lm). The HeaderText=""
Sw. WriteLine (" ")
Sw. Flush ()
'If DataGridView3. Columns (lm). The Name=lm Then
'DataGridView3. Columns (lm). The Visible=False

Next
Fs. The Close ()
MessageBox. Show (" export success ", "prompt")
End the If
End Sub

The database directly export CSV file

After debugging tools export CSV file

Compared with direct export "" and, less time format is not for the great spirit guide

CodePudding user response:

Debugging, CRH (34) is the quotes

CodePudding user response:

reference 1/f, guiyang horse Ma Shanfu plugging waterproof engineering professional maintenance of swimming pool response:
debugging, CRH (34) is quotes
useless tried is to have a problem with a direct export of text format

CodePudding user response:

I saw your code, the feeling is no problem, I will you a copy of the code on my project, commented out moban="template"
SFD. FileName=RadioButton1. Text & amp; Moban, the two other code, the export is normal,

CodePudding user response:

"Org", "Line", "DJ", "Model", "Station", "MaterialNo", "CLID", "Result", "CreatedOn," "CreatedBy,"
"439", "LDCP1212 P3067012", ""," 700-015128-0000 ", "Wave Soldering", "700-014828-0100", "2155030164 ns98200961", "Alert", "12/18/2019 11:33:57 AM", "zhangpeng,"
"439", "LDCP1212 P3067267", ""," 700-015128-0000 ", "Wave Soldering", "641-001064-0000", "LD000000000020668795", "Pass", "12/18/2019 11:36:33 AM", "zhangpeng,"
"439", "LDCP1201 P3067012", ""," 700-015128-0000 ", "Potting", "641-001064-0000", "LD000000000020742826", "Alert", "12/18/2019 1:34:13 PM" and "zhangpeng,"
This is the part I export the data, the data that I had random test data

CodePudding user response:

Pause, or use the debug. Print (s) debugging,

CodePudding user response:

I made a Excel in import and export, and some small problems in dealing with the CSV, then simply as XLS,
See
"How in Visual Basic. NET use ADO.NET to retrieve and modify the record" in the Excel workbook, https://blog.csdn.net/cdbqss1/article/details/5623515? Utm_source=app
  • Related