Archive for Tháng Chín 10, 2008
Select SQL Column name contains “.” characters
Select [Co#lumn] from myTable
Export Data to CSV file
Private Sub SaveGridDataInFile(ByRef fName As String)
Dim I As Integer = 0
Dim j As Integer = 0
Dim cellvalue$
Dim rowLine As String = “”
Try
Dim objWriter As New System.IO.StreamWriter(fName, True, System.Text.Encoding.Default)
For j = 0 To (DataGridView1.Rows.Count – 2)
For I = 0 To (DataGridView1.Columns.Count – 1)
If Not TypeOf DataGridView1.CurrentRow.Cells.Item(I).Value Is DBNull Then
cellvalue = DataGridView1.Item(I, j).Value.ToString
Else
cellvalue = “”
End If
rowLine = rowLine + cellvalue + “,”
Next
objWriter.WriteLine(rowLine)
rowLine = “”
Next
objWriter.Close()
MsgBox(“保存ファイル成功”)
Catch e As Exception
MessageBox.Show(“Error occured while writing to the file.” + e.ToString())
Finally
FileClose(1)
End Try
End Sub
Add Rows Index to datagridview
Private Sub DataGridView1_CellPainting(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellPaintingEventArgs) Handles DataGridView1.CellPainting
Dim sf As New StringFormat
sf.Alignment = StringAlignment.Center
If e.ColumnIndex < 0 AndAlso e.RowIndex >= 0 AndAlso e.RowIndex < datatabel(1).Rows.Count Then
e.PaintBackground(e.ClipBounds, True)
e.Graphics.DrawString((e.RowIndex + 1).ToString, Me.Font, Brushes.Black, e.CellBounds, sf)
e.Handled = True
End If
End Sub