Extracted into a dataset, if XXX is fixed the filename and file placed in advance is not error Dim SQL As String="select * from XXX"
But if the dynamic, when after the fileupload uploading was used to extract the CSV will be an error,
' '200325171608. CSV' is not a valid name, please make sure it does not contain invalid characters or punctuation, and did not name is too long,
Note: during the execution of the current Web request, an unhandled exception, please check the stack trace, to learn about the errors and mistakes in the code of the source of detailed information,
Exception details: System. Data. The OleDb. OleDbException: "' 200325171608. CSV 'is not a valid name, please make sure it does not contain invalid characters or punctuation, and did not name is too long,
The code is as follows,
'...
Dim filename As String=Now. ToString (" yyMMddHHmmss ") + "CSV"
Dim savePath As String=Server. MapPath ((ExcelUp \ "") + filename)
FileUpload1. SaveAs (savePath)
Dim mp As String=Server. MapPath ((" ExcelUp \ "))
Dim strConn As String=the String. Format (" Provider=Microsoft. Jet. The OLEDB. 4.0. Extended Properties='text; HDR=Yes; FMT=Delimited; CharacterSet=65001 '; Data Source='" & amp; Mp & amp; "'")
Dim conn As New OleDbConnection (strConn)
Dim dt1 As New DataTable ()
Dim SQL As String="select * from '" & amp; Filename & amp; "'
"
Conn. The Open ()
Dim the Dr As New OleDbDataAdapter (SQL, conn)
Dim ds As New DataSet ()
Dr. Fill (ds, "table1")
Dt1=ds. Tables (" table1 ")
If dt1. Rows. Count & gt; 1 Then
GridView2. The DataSource=dt1
GridView2. DataBind ()
End the If
CodePudding user response:
Problem is solved, a variable reference, (" + filename + ")CodePudding user response:
I used to
Dim mp As String=Server. MapPath (" ~/ExcelUp/" + filename);
This kind of form.