ช่วยหน่อยครับ ทำไม่เวลากด UPDATE แล้ว มันเก็บ DATA ลง SQL แต่มันไม่แสดง DATE ให้ดูอะครับ ช่วยดูให้หน่อยครับ
ช่วยหน่อยครับ พอกด UPDATE แล้วเก็บ DATA ลง SQL แต่มันไม่แสดง DATE ให้ดูอะครับ ช่วยดูให้หน่อยครับทำไงให้แสดง DATE ให้ดูอะครับ ผมตกอะไรไปหรือป่าว ขอบคุณล่วงหน้าครับ
[upload.aspx]
Code (ASP)
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Upload.aspx.vb" Inherits="Upload" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<p>
</p>
<br />
<asp:Label ID="Label1" runat="server" Text="Policy" Width="45px"></asp:Label>
<asp:FileUpload ID="FUL_Upload1" runat="server" BorderColor="Black" />
<asp:Button ID="bt_upload1" runat="server" Text="Upload" /><br />
<asp:Label ID="Label2" runat="server" Text="Endorse"></asp:Label> <asp:FileUpload ID="FUL_Upload2" runat="server" BorderColor="Black" />
<asp:Button ID="bt_upload2" runat="server" Text="Upload" /><br />
<br />
<asp:Repeater id="myRepeater" runat="server">
<HeaderTemplate>
<table border="1">
<tr>
<th>insure_id</th>
<th>policy_id</th>
<th>insure_date</th>
<th>effective_date</th>
<th>expiry_date</th>
<th>car_id</th>
<th>province_id</th>
<th>nummernschild</th>
<th>vin</th>
<th>fridname</th>
<th>surname</th>
<th>endorse_date</th>
<th>endorsrnummer</th>
<th>report_id</th>
<th>error</th>
<th>error_id</th>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td align="center"><%#Container.DataItem(0)%></td>
<td align="center"><%#Container.DataItem(1)%></td>
<td align="center"><%#Container.DataItem(2)%></td>
<td align="center"><%#Container.DataItem(3)%></td>
<td align="center"><%#Container.DataItem(4)%></td>
<td align="center"><%#Container.DataItem(5)%></td>
<td align="center"><%#Container.DataItem(6)%></td>
<td align="center"><%#Container.DataItem(7)%></td>
<td align="center"><%#Container.DataItem(8)%></td>
<td><%#Container.DataItem(9)%></td>
<td><%#Container.DataItem(10)%></td>
<td align="center"><%#Container.DataItem(11)%></td>
<td align="center"><%#Container.DataItem(12)%></td>
<td align="center"><%#Container.DataItem(13)%></td>
<td align="center"><%#Container.DataItem(14)%></td>
<td align="center"><%#Container.DataItem(15)%></td>
</tr>
</ItemTemplate>
</asp:Repeater>
</div>
</form>
</body>
</html>
__________________________________________________________________________________
[upload.aspx.vb]
Code (VB.NET)
Imports System.IO
Imports System.Data
Imports System.Data.SqlClient
Imports system.data.oledb
Partial Class Upload
Inherits System.Web.UI.Page
Private Const ConStr As String = "Data Source=192.168.4.17;Initial Catalog=MIS;Persist Security Info=True;User ID=sa;Connect Timeout=7200;password=sa;Connection lifetime=0;Max Pool Size=100;Min Pool Size=10"
Friend Const ConStrInformix As String = "Dsn=gis_motor;uid=mis_user;database=mis;host=192.168.4.5;srvr=online8;serv=1532;pro=onsoctcp;cloc=th_th.thai620;dloc=th_th.thai620;vmb=1;curb=0;scur=0;icur=0;oac=-0;optofc=0;rkc=0;odtyp=0;ddfp=0"
Protected Sub bt_upload1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles bt_upload1.Click
Dim objFSO, oInStream, sRows, arrRows
Dim Conn, objExec
Dim sFileName
Dim connstring
Dim sSplit() As String
Dim strFileUse As String
Dim dt_file As New DataTable
Dim CurrentLine As String
Dim strValue() As String
Dim sqlTran As SqlTransaction
dt_file.Columns.Add("policy_report", GetType(String))
''*** Open Files ***'
objFSO = Server.CreateObject("Scripting.FileSystemObject")
sFileName = Server.MapPath("temp\policy.txt")
FUL_Upload1.PostedFile.SaveAs(sFileName)
oInStream = objFSO.OpenTextFile(sFileName, 1, False)
'*** open Connect to Microsoft SQL Server Management Studio ***'
Dim sqlcmd As New SqlCommand
Dim sqlcon As New SqlConnection(ConStr)
If sqlcon.State = ConnectionState.Closed Then sqlcon.Open()
sqlTran = sqlcon.BeginTransaction
sqlcmd.Transaction = sqlTran
sqlcmd.CommandTimeout = 7200
sqlcmd.Connection = sqlcon
sqlcmd.CommandType = CommandType.Text
Try
Do Until oInStream.AtEndOfStream
sRows = oInStream.readLine
arrRows = Split(sRows, "|")
'*** Insert to table policy_report ***'
If arrRows(11) = "0" Then
Dim strSQL = ""
strSQL = strSQL & "INSERT INTO policy_report "
strSQL = strSQL & "(insure_id,policy_id,insure_date,effective_date,expiry_date,car_id,province_id,nummernschild,vin,fridname,surname,error_id,error) "
strSQL = strSQL & "VALUES "
strSQL = strSQL & "('" & arrRows(0) & "','" & arrRows(1) & "','" & arrRows(2) & "' "
strSQL = strSQL & ",'" & arrRows(3) & "','" & arrRows(4) & "','" & arrRows(5) & "' "
strSQL = strSQL & ",'" & arrRows(6) & "','" & arrRows(7) & "','" & arrRows(8) & "' "
strSQL = strSQL & ",'" & arrRows(9) & "','" & arrRows(10) & "','" & arrRows(11) & "' "
strSQL = strSQL & ",'" & arrRows(12) & "') "
sqlcmd.CommandText = strSQL
sqlcmd.ExecuteNonQuery()
End If
Loop
sqlTran.Commit()
'lbl_error.Text &= "Transfer Data Complete " & CStr(Session("dt_note").rows.count) & " Record(s)"
Catch ex As Exception
'lbl_error.Text = "Error Transfer Record " + vbCrLf + ex.Message
sqlTran.Rollback()
Exit Sub
Finally
If sqlcon.State = ConnectionState.Open Then sqlcon.Close()
End Try
oInStream.Close()
'Conn.Close()
oInStream = Nothing
Conn = Nothing
End Sub
Protected Sub bt_upload2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles bt_upload2.Click
Dim objFSO, oInStream, sRows, arrRows
Dim Conn, objExec
Dim sFileName
Dim connstring
Dim sSplit() As String
Dim strFileUse As String
Dim dt_file As New DataTable
Dim CurrentLine As String
Dim strValue() As String
Dim sqlTran As SqlTransaction
dt_file.Columns.Add("endorse_report", GetType(String))
''*** Open Files ***'
objFSO = Server.CreateObject("Scripting.FileSystemObject")
sFileName = Server.MapPath("temp\endorse.txt")
FUL_Upload2.PostedFile.SaveAs(sFileName)
oInStream = objFSO.OpenTextFile(sFileName, 1, False)
'*** open Connect to Microsoft SQL Server Management Studio ***'
Dim sqlcmd As New SqlCommand
Dim sqlcon As New SqlConnection(ConStr)
If sqlcon.State = ConnectionState.Closed Then sqlcon.Open()
sqlTran = sqlcon.BeginTransaction
sqlcmd.Transaction = sqlTran
sqlcmd.CommandTimeout = 7200
sqlcmd.Connection = sqlcon
sqlcmd.CommandType = CommandType.Text
Try
Do Until oInStream.AtEndOfStream
sRows = oInStream.readLine
arrRows = Split(sRows, "|")
'*** Insert to table endorse_report ***'
If arrRows(11) = "0" Then
Dim strSQL = ""
strSQL = strSQL & "INSERT INTO endorse_report "
strSQL = strSQL & "(insure_id,policy_id,insure_date,effective_date,expiry_date,car_id,province_id,nummernschild,vin,fridname,surname,error_id,error) "
strSQL = strSQL & "VALUES "
strSQL = strSQL & "('" & arrRows(0) & "','" & arrRows(1) & "','" & arrRows(2) & "' "
strSQL = strSQL & ",'" & arrRows(3) & "','" & arrRows(4) & "','" & arrRows(5) & "' "
strSQL = strSQL & ",'" & arrRows(6) & "','" & arrRows(7) & "','" & arrRows(8) & "' "
strSQL = strSQL & ",'" & arrRows(9) & "','" & arrRows(10) & "','" & arrRows(11) & "' "
strSQL = strSQL & ",'" & arrRows(12) & "') "
sqlcmd.CommandText = strSQL
sqlcmd.ExecuteNonQuery()
End If
Loop
sqlTran.Commit()
'lbl_error.Text &= "Transfer Data Complete " & CStr(Session("dt_note").rows.count) & " Record(s)"
Catch ex As Exception
'lbl_error.Text = "Error Transfer Record " + vbCrLf + ex.Message
sqlTran.Rollback()
Exit Sub
Finally
If sqlcon.State = ConnectionState.Open Then sqlcon.Close()
End Try
oInStream.Close()
'Conn.Close()
oInStream = Nothing
Conn = Nothing
End Sub
Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
Dim dt As DataTable
'*** DataTable ***'
dt = ReadTXT()
myRepeater.DataSource = dt
myRepeater.DataBind()
End Sub
Function ReadTXT() As DataTable
Dim dt As New DataTable
Dim dr As DataRow
dt.Columns.Add("insure_id")
dt.Columns.Add("policy_id")
dt.Columns.Add("insure_date")
dt.Columns.Add("effective_date")
dt.Columns.Add("expiry_date")
dt.Columns.Add("car_id")
dt.Columns.Add("province_id")
dt.Columns.Add("nummernschild")
dt.Columns.Add("vin")
dt.Columns.Add("fridname")
dt.Columns.Add("surname")
dt.Columns.Add("endorse_date")
dt.Columns.Add("endorsrnummer")
dt.Columns.Add("report_id")
dt.Columns.Add("error")
dt.Columns.Add("error_id")
Dim StrWer As StreamReader
Dim strLine As String
StrWer = File.OpenText(Server.MapPath("c/compulsory/policy.txt"))
Do Until StrWer.EndOfStream
strLine = StrWer.ReadLine()
If Trim(strLine) <> "" Then
dr = dt.NewRow
dr("insure_id") = Split(strLine, "|")(0)
dr("policy_id") = Split(strLine, "|")(1)
dr("insure_date") = Split(strLine, "|")(2)
dr("effective_date") = Split(strLine, "|")(3)
dr("expiry_date") = Split(strLine, "|")(4)
dr("car_id") = Split(strLine, "|")(5)
dr("province_id") = Split(strLine, "|")(6)
dr("nummernschild") = Split(strLine, "|")(7)
dr("vin") = Split(strLine, "|")(8)
dr("fridname") = Split(strLine, "|")(9)
dr("surname") = Split(strLine, "|")(10)
dr("endorse_date") = Split(strLine, "|")(11)
dr("endorsrnummer") = Split(strLine, "|")(12)
dr("report_id") = Split(strLine, "|")(13)
dr("error") = Split(strLine, "|")(14)
dr("error_id") = Split(strLine, "|")(15)
dt.Rows.Add(dr)
End If
Loop
StrWer.Close()
Return dt
End Function
End Class
__________________________________________________________________________________Tag : ASP
Date :
2010-11-15 09:53:02
By :
TAE
View :
914
Reply :
3
ให้แสดง data นะครับ ไม่ช่าย date พิมพ์ผิดอะครับ ขอโทษครับ
Date :
2010-11-15 10:21:03
By :
TAE
ไม่มี ERROR นะครับ DATA ก็เก็บได้ปกติครับ
แต่มันไม่โชว์ข้อมูล เรียกมันขึ้นมาโชว์อย่างไงอะครับ ขอ Code ได้ไหมอะครับ ตัวอย่างก็ได้ครับ
Date :
2010-11-15 10:44:17
By :
TAE
DATA ลง SQL แต่มันไม่โชว์ในหน้าGridView ให้เข้าไปตั้งค่าที่ ProPerties ของ Grid คะ ใส่ตรง "dataKeyName" โดยนำคีย์หลักนั้นมาใส่คะ หลังจากนั้นให้เข้าไปตั้งค่าที่ Grid ในแต่ละ Field โดยใส่ตรง "DataField" ตังค่าให้ตรงกับฐานข้อมูลคะ น่าจะได้แล้วนะคะ
Date :
2010-11-15 11:17:49
By :
PUY
Load balance : Server 04