【发布时间】:2019-12-14 13:52:14
【问题描述】:
我正在尝试使用 CSV 文件将多条记录添加到数据库表中。如果我删除 try/catch,我会收到此错误:
System.IO.FileNotFoundException
HResult=0x80070002
Message=Could not find file 'C:\Program Files (x86)\IIS Express\BJ_and_TS.csv'.
Source=<Cannot evaluate the exception source>
StackTrace:
<Cannot evaluate the exception stack trace>
为什么不保存文件?我还有什么做错的?这是我的代码隐藏:
Private Sub BTN_Upload_Click(sender As Object, e As EventArgs) Handles BTN_Upload.Click
Dim context As New MusicContext
Try
If FU_CSV.HasFile Then
FU_CSV.SaveAs(Server.MapPath("~/Content/Docs/Data/" & FU_CSV.FileName))
Dim csvData = From line As String In File.ReadAllLines(FU_CSV.FileName)
Skip 1
Let CR = line.Split(",")
Select New Album With {
.AlbumName = CR(0),
.ImagePath = CR(1),
.ReleaseDate = CDate(CR(2)),
.UnitPrice = CDec(CR(3)),
.BandID = CInt(CR(4)),
.GenreID = CInt(CR(5))
}
For Each a As Album In csvData
context.Albums.Add(a)
context.SaveChanges()
Next
'ClientScript.RegisterStartupScript(Page.GetType(), "BulkAlbums", "$('#BulkRecords').modal();", True)
End If
Catch ex As Exception
End Try
End Sub
【问题讨论】:
标签: asp.net vb.net linq webforms