เกิดจากอะไรเกี่ยวกับฐานข้อมูลด้วยหรือเปล่า This key is already associated with an element of this collection ตอนอัพเดทเพื่อส่งค่าไป key มี 2 ตัว
ไม่เคยเจอแบบนี้นะคับ แต่เท่าที่ดูตาม Error ก็น่าแสดงว่า มีการส่งไปผิด อาจจะ ซ้ำซ้อน หรือไง ไม่ทราบ ไม่เคยเจอ
ลองส่งไปทีละตัวดูนะคับ ส่งแค่ a ไปแล้วรับได้ไหม ไม่ error ต่อไปก็ส่ง a,b ไป ว่ารับได้ไหม ถ้ารับได้ก็ Debug ลำดับ
ต่อไปคับ
Date :
2010-02-17 12:51:49
By :
inanosms
มีค่ามานะคะแต่ทำไมมันฟ้อง file upload
This key is already associated with an element of this collection
Date :
2010-02-17 13:38:50
By :
jpy
file upload
Code (ASP)
<%
Sub BuildUploadRequest(RequestBin)
PosBeg = 1
PosEnd = InstrB(PosBeg,RequestBin,getByteString(chr(13)))
boundary = MidB(RequestBin,PosBeg,PosEnd-PosBeg)
boundaryPos = InstrB(1,RequestBin,boundary)
Do until (boundaryPos=InstrB(RequestBin,boundary & getByteString("--")))
Dim UploadControl
Set UploadControl = CreateObject("Scripting.Dictionary")
Pos = InstrB(BoundaryPos,RequestBin,getByteString("Content-Disposition"))
Pos = InstrB(Pos,RequestBin,getByteString("name="))
PosBeg = Pos+6
PosEnd = InstrB(PosBeg,RequestBin,getByteString(chr(34)))
Name = getString(MidB(RequestBin,PosBeg,PosEnd-PosBeg))
PosFile = InstrB(BoundaryPos,RequestBin,getByteString("filename="))
PosBound = InstrB(PosEnd,RequestBin,boundary)
If PosFile<>0 AND (PosFile<PosBound) Then
PosBeg = PosFile + 10
PosEnd = InstrB(PosBeg,RequestBin,getByteString(chr(34)))
FileName = getString(MidB(RequestBin,PosBeg,PosEnd-PosBeg))
UploadControl.Add "FileName", FileName
Pos = InstrB(PosEnd,RequestBin,getByteString("Content-Type:"))
PosBeg = Pos+14
PosEnd = InstrB(PosBeg,RequestBin,getByteString(chr(13)))
ContentType = getString(MidB(RequestBin,PosBeg,PosEnd-PosBeg))
UploadControl.Add "ContentType",ContentType
PosBeg = PosEnd+4
PosEnd = InstrB(PosBeg,RequestBin,boundary)-2
Value = MidB(RequestBin,PosBeg,PosEnd-PosBeg)
Else
Pos = InstrB(Pos,RequestBin,getByteString(chr(13)))
PosBeg = Pos+4
PosEnd = InstrB(PosBeg,RequestBin,boundary)-2
Value = getString(MidB(RequestBin,PosBeg,PosEnd-PosBeg))
End If
UploadControl.Add "Value" , Value
UploadRequest.Add name, UploadControl 'บรรทัดที่ error
BoundaryPos=InstrB(BoundaryPos+LenB(boundary),RequestBin,boundary)
Loop
End Sub
Function getByteString(StringStr)
For i = 1 to Len(StringStr)
char = Mid(StringStr,i,1)
getByteString = getByteString & chrB(AscB(char))
Next
End Function
Function getString(StringBin)
getString =""
For intCount = 1 to LenB(StringBin)
getString = getString & chr(AscB(MidB(StringBin,intCount,1)))
Next
End Function
%>
file aaa ส่งค่าไป
ค่าที่ส่งไป
Code (VB.NET)
<!--#include file=upload.asp-->
<%
len1=Len(request("url"))-InstrRev(request("url"),"/")
pathinfo=Server.mappath(Request.ServerVariables("PATH_INFO"))
pathEnd = Len(pathinfo)-len1
filepath=left(pathinfo,pathEnd) & "image_personal\"
Response.Expires=0
Response.Buffer = TRUE
Response.Clear
byteCount = Request.TotalBytes
RequestBin = Request.BinaryRead(byteCount)
Dim UploadRequest
Set UploadRequest = CreateObject("Scripting.Dictionary")
BuildUploadRequest RequestBin
Id = UploadRequest.Item("Id_").Item("Value")
Title_id = UploadRequest.Item("Title_id").Item("Value")
%>
Error
Error Type:
Microsoft VBScript runtime (0x800A01C9)
This key is already associated with an element of this collection
/test/upload.asp, line 37
ตรงที่บันทัดนี้ error
UploadRequest.Add name, UploadControl บรรทัดสีแดง
Date :
2010-02-18 14:50:17
By :
jpy
อันนี้โปรเจ็คเก่า เอาไปดู ไปก็อบ ไปใช้
Conn.asp
<%
connstr = "Driver={SQL Server};Server=10.0.102.9;Database=MyDatabase;UID=MyUser;Pwd=MyPassword"
Set Conn = Server.CreateObject("ADODB.Connection")
Conn.Open ConnStr
%>
CloseConn.asp
<%
Conn.Close
Set Conn = Nothing
%>
AddFile.asp
<!--#include file="include/conn.asp" -->
<html>
<head>
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
<meta http-equiv="content-Type" content="text/html; charset=windows-874">
<meta name="Author" content="tungman">
<meta name="Keywords" content="">
<meta name="Description" content="">
<title>::: Upload File :::</title>
</head>
<SCRIPT LANGUAGE="JavaScript">
// Begin
// คำสั่ง java script สำหรับการตรวจสอบการป้อนข้อมูล
function validate(){
if (document.upload.detail.value=="") {
alert("กรุณาป้อน คำอธิบายของ file..!");
document.upload.detail.focus();
return false;
}
if (document.upload.file.value=="") {
alert("กรุณาเลือก File ที่ต้องการ upload..!");
document.upload.file.focus();
return false;
}
if (confirm("คุณต้องการส่ง file ที่คุณเลือกหรือไม่?")) {
return true;
} else {
return false;
}
}
function MM_goToURL() { //v3.0
var i,
args = MM_goToURL.arguments;
document.MM_returnValue = false;
for (i = 0; i<(args.length-1); i += 2)
eval(args[i]+".location='" + args[i+1] + "'");
}
// End -->
</script>
<body>
<!-- Insert HTML here -->
<%
Set RSproject = Conn.Execute("Select [GOVSERV_PROJECT].[PROJECT_NAME], [GOVSERV_PROJECT].[PROJECT_ID], [GOVSERV_PROJECT].[PROJECT_FILE], [GOVSERV_DIVISION].[DIVISION_SNAME] From [GOVSERV_PROJECT] Inner Join [GOVSERV_DIVISION] On [GOVSERV_DIVISION].[DIVISION_ID] = [GOVSERV_PROJECT].[DIVISION_ID] Where [GOVSERV_PROJECT].[PROJECT_ID]="& Request("id"))
%>
<form name="upload" action="uploadfile.asp" method="post" enctype="multipart/form-data" onsubmit="return validate();">
<input type="hidden" name="id" value="<%=RSproject("PROJECT_ID")%>">
<table width="100%" border="0">
<tr>
<td width="100%" colspan="2"><b><%=RSproject("PROJECT_NAME")%> - <%=RSproject("DIVISION_SNAME")%></b></td>
</tr>
<tr>
<td width="30%" nowrap>คำอธิบาย file:</td>
<td width="70%"><input type="text" name="detail"></td>
</tr>
<tr>
<td nowrap>File ที่ต้องการ Upload:</td>
<td><input type="file" name="file"> <font color="#FF0000">* ขนาดไฟล์ต้องไม่เกิน 10 Mbytes</font></td>
</tr>
<tr>
<td> </td>
<td><input type="submit" name="Submit" value="Submit">
<input type="reset" name="Submit2" value="Reset">
<input type="button" value=" Back " onClick="MM_goToURL('parent','showfile.asp?id=<%=RSproject("PROJECT_ID")%>');return document.MM_returnValue;">
</td>
</tr>
</table>
</form>
</body>
</html>
<!--#include file="include/closeconn.asp" -->
UploadFile.asp
<!--#include file="include/conn.asp" -->
<%
' Author Philippe Collignon
' Email [email protected]
' Credit ให้เขาด้วยนะครับกรุณาอย่าเอาออก
Response.Expires = 0
Response.Buffer = True
Response.Clear
byteCount = Request.TotalBytes
RequestBin = Request.BinaryRead(byteCount)
Dim UploadRequest
Set UploadRequest = CreateObject("Scripting.Dictionary")
BuildUploadRequest RequestBin
contentType = UploadRequest.Item("file").Item("ContentType")
filepathname = UploadRequest.Item("file").Item("FileName")
filename = Right(filepathname,Len(filepathname)-InstrRev(filepathname,"\"))
values = UploadRequest.Item("file").Item("Value")
detail = UploadRequest.Item("detail").Item("Value")
id = UploadRequest.Item("id").Item("Value")
Set ScriptObject = Server.CreateObject("Scripting.FileSystemObject")
FilePath = Server.MapPath("excel") & "\" & filename
Set MyFile = ScriptObject.CreateTextFile(FilePath)
For i = 1 to LenB(values)
MyFile.Write chr(AscB(MidB(values,i,1)))
Next
MyFile.Close
%>
<font face='ms Sans serif' size=-1>
<!--Upload ไปยัง path :<%=filePath%><br>-->
ชื่อ file : </b><%=filename%><br>
คำอธิบาย : <%=detail%><br>
<a href="showfile.asp?id=<%=id%>">คลิกที่นี่เพื่อย้อนกลับ</a>
<!--#include file="inc_upload.asp"-->
<%
Conn.Execute("Update [GOVSERV_PROJECT] Set [PROJECT_FILE]=1 Where [PROJECT_ID]="& id)
Conn.Execute("Insert Into [PROJECT_FILE] ([PROJECT_ID], [FILE_NAME], [FILE_DETAIL]) Values ("& id &", '"& filename &"', '"& detail &"')")
%>
<!--#include file="include/closeconn.asp" -->
inc_upload.asp
<%
' Author Philippe Collignon
' Email [email protected]
' Credit ให้เขาด้วยนะครับกรุณาอย่าเอาออก
Sub BuildUploadRequest(RequestBin)
PosBeg = 1
PosEnd = InstrB(PosBeg,RequestBin,getByteString(chr(13)))
boundary = MidB(RequestBin,PosBeg,PosEnd-PosBeg)
boundaryPos = InstrB(1,RequestBin,boundary)
Do until (boundaryPos=InstrB(RequestBin,boundary & getByteString("--")))
Dim UploadControl
Set UploadControl = CreateObject("Scripting.Dictionary")
Pos = InstrB(BoundaryPos,RequestBin,getByteString("Content-Disposition"))
Pos = InstrB(Pos,RequestBin,getByteString("name="))
PosBeg = Pos+6
PosEnd = InstrB(PosBeg,RequestBin,getByteString(chr(34)))
Name = getString(MidB(RequestBin,PosBeg,PosEnd-PosBeg))
PosFile = InstrB(BoundaryPos,RequestBin,getByteString("filename="))
PosBound = InstrB(PosEnd,RequestBin,boundary)
If PosFile<>0 AND (PosFile<PosBound) Then
PosBeg = PosFile + 10
PosEnd = InstrB(PosBeg,RequestBin,getByteString(chr(34)))
FileName = getString(MidB(RequestBin,PosBeg,PosEnd-PosBeg))
UploadControl.Add "FileName", FileName
Pos = InstrB(PosEnd,RequestBin,getByteString("Content-Type:"))
PosBeg = Pos+14
PosEnd = InstrB(PosBeg,RequestBin,getByteString(chr(13)))
ContentType = getString(MidB(RequestBin,PosBeg,PosEnd-PosBeg))
UploadControl.Add "ContentType",ContentType
PosBeg = PosEnd+4
PosEnd = InstrB(PosBeg,RequestBin,boundary)-2
Value = MidB(RequestBin,PosBeg,PosEnd-PosBeg)
Else
Pos = InstrB(Pos,RequestBin,getByteString(chr(13)))
PosBeg = Pos+4
PosEnd = InstrB(PosBeg,RequestBin,boundary)-2
Value = getString(MidB(RequestBin,PosBeg,PosEnd-PosBeg))
End If
UploadControl.Add "Value" , Value
UploadRequest.Add name, UploadControl
BoundaryPos=InstrB(BoundaryPos+LenB(boundary),RequestBin,boundary)
Loop
End Sub
Function getString(StringBin)
getString =""
For intCount = 1 to LenB(StringBin)
getString = getString & chr(AscB(MidB(StringBin,intCount,1)))
Next
End Function
'String to byte string conversion
Function getByteString(StringStr)
For i = 1 to Len(StringStr)
char = Mid(StringStr,i,1)
getByteString = getByteString & chrB(AscB(char))
Next
End Function
%>
Date :
2010-02-18 17:00:06
By :
tungman
มีไฟล์ฐานข้อมูลมั้ยครับ ขอด้วย
Date :
2010-05-12 15:59:47
By :
อาท
Load balance : Server 00