hi all, just a question. I have created this code to export my data grid to excel. but I would want to know how to make it in a way that it will automatically create new .CSV with date when I export it.
below is the code
''create empty string
Dim thecsvfile As String = String.Empty
'Add your Heading With empty string seprated by comma to make space of cell from begining
thecsvfile += ","c & ","c & "User Details" & ","c & vbCr & vbLf
thecsvfile += "" & ","c & vbCr & vbLf
thecsvfile += "" & ","c & vbCr & vbLf
thecsvfile += "" & ","c & vbCr & vbLf
'get the column headers
For Each column As DataGridViewColumn In Item_listDataGridView1.Columns
thecsvfile = thecsvfile & column.HeaderText & ","
Next
'trim the last comma
thecsvfile = thecsvfile.TrimEnd(",")
'Add the line to the output
thecsvfile = thecsvfile & vbCr & vbLf
'get the rows
For Each row As DataGridViewRow In Item_listDataGridView1.Rows
'get the cells
For Each cell As DataGridViewCell In row.Cells
thecsvfile = thecsvfile & cell.FormattedValue.replace(",", "") & ","
Next
'trim the last comma
thecsvfile = thecsvfile.TrimEnd(",")
'Add the line to the output
thecsvfile = thecsvfile & vbCr & vbLf
Next
'write the file
My.Computer.FileSystem.WriteAllText("C:\Inventory System\Inventory Data.csv", thecsvfile, False)
MessageBox.Show("File has been Saved to C:\Inventory System\Inventory Data.csv ")