HOME > .NET Framework > Forum > ช่วยดู code Upload file csv to DB ให้หน่อยค๊าบ มี error ! Error: Column 'Day' does not belong to table .Error: Column 'Day' does not belong to table .
ช่วยดู code Upload file csv to DB ให้หน่อยค๊าบ มี error ! Error: Column 'Day' does not belong to table .Error: Column 'Day' does not belong to table .
คือผมเขียนไว้ไม่ทราบว่าถูกหรือเปล่าครับ มันมี error ตรงส่วน insert ด้วย ซึ่งชื่อ field ก็ตรงกัน หรือว่าส่วนอื่นผิดครับ
Code:
Code (VB.NET)
Protected Sub BtnUpload_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
If (CheckFile1.Checked) = True Then
Dim UlFileName As String
Dim i As Integer
UlFileName = FileUpload1.PostedFile.FileName
Dim objConn As OleDbConnection = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source= " + Path.GetDirectoryName(UlFileName) + ";Extended Properties=""Text;HDR=YES;FMT=Delimited""")
objConn.Open()
Dim strQuery As String = "Select * From [" + Path.GetFileName(UlFileName) + "]"
Dim da As OleDbDataAdapter = New OleDbDataAdapter(strQuery, objConn)
Dim dt As New System.Data.DataTable()
da.Fill(dt)
''*** Insert to Database ***'
Dim strSQL As String
Dim objCmd As SqlCommand
Dim opjConn1 As SqlConnection = New SqlConnection("Data Source=CV_CHALERMPOL;Initial Catalog=WFM_Report;User Id=sa;Password=sa;")
opjConn1.Open()
For i = 0 To dt.Rows.Count - 1
Try
strSQL = "INSERT INTO Temp_Activity_Data(Day,Organization,Employee,ShiftStart,ShiftEnd,ScheduledActivity,SActivityStart," & _
"SActivityEnd,ScheduledTime,ActualActivity,AActivityStart,AActivityEnd,ActualTime) " & _
"VALUES ('" & dt.Rows(i)("Day") & "','" & dt.Rows(i)("Organization") & "' " & _
",'" & dt.Rows(i)("Employee") & "','" & dt.Rows(i)("ShiftStart") & "' " & _
",'" & dt.Rows(i)("ShiftEnd") & "','" & dt.Rows(i)("ScheduledActivity") & "' " & _
",'" & dt.Rows(i)("SActivityStart") & "','" & dt.Rows(i)("SActivityEnd") & "' " & _
",'" & dt.Rows(i)("ScheduledTime") & "','" & dt.Rows(i)("ActualActivity") & "' " & _
",'" & dt.Rows(i)("AActivityStart") & "','" & dt.Rows(i)("AActivityEnd") & "' " & _
",'" & dt.Rows(i)("ActualTime") & "') "
objCmd = New SqlCommand(strSQL, opjConn1)
objCmd.ExecuteNonQuery()
Catch ex As Exception
Response.Write("Error: " & ex.Message)
End Try
Next
objConn.Close()
opjConn1.Close()
objConn = Nothing
opjConn1 = Nothing
End If
End Sub
มันขึ้น error ว่า
Code
Error: Column 'Day' does not belong to table .Error: Column 'Day' does not belong to table .
รบกวนด้วยนะครับ ขอบคุณครับ
Tag : .NET, Ms SQL Server 2005, Web (ASP.NET), VB.NET, VS 2008 (.NET 3.x)