ช่วยด้วยค่ะ!!!!!!!!!!!!! เกี่ยวกับการ update ข้อมูลใน database ใน mssql (SQL Server)
หนูมีคำถามค่ะ แก้ไม่ตก คือ
1)หนูต้องการจะดึงค่า TVID จากดาตาเบส มาใส่ในtextfield ของหน้า edit ค่ะ
2)ช่วยดูcodeหน้า edit_doneหน่อยค่ะ ... คือมันไม่ได้อ่ะค่ะ
<<<<<<<<<<<edit>>>>>>>>>>>>>
Code (ASP)
<html>
<!--#include file="conndb.inc"-->
<head>
<title>EDIT</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<form name="test1" method="post" action="edit_done.asp">
</head>
<body>
<div align="center">
<p><strong>EDIT</strong></p>
<table width="733" border="1">
<!--DWLayoutTable-->
<tr>
<td width="723"><p>TV_ID
<input name="id" type="text" id="id" value=response.write &obj("TV_ID")&"' >
</p></td>
</tr>
<tr>
<td><p>IRD_No.
<input name="IRD_No" type="text" id="IRD_No" value = '"&response.write obj("IRD_No")&"'>
</p></td>
</tr>
<tr>
<td><p>Satellite
<select name="a1">
<option value="Thaicom 4">Thaicom 4</option>
<option value="Thaicom 5">Thaicom 5</option>
<option value="NSS6">NSS6</option>
</select>
</p>
</td>
</tr>
<tr>
<td><p>Antenna Size
<select name="a2">
<option value="60 cm.">60 cm.</option>
<option value="75 cm.">75 cm.</option>
<option value="1.2 m.">1.2 m.</option>
<option value="1.5 m.">1.5 m.</option>
<option value="1.7 m.">1.7 m.</option>
<option value="3 m.">3 m.</option>
</select>
</p></td>
</tr>
<tr>
<td><p>Polarization
<select name="a3">
<option value="Vertical">Vertical</option>
<option value="Horizontal">Horizontal</option>
</select>
</p></td>
</tr>
<tr>
<td><p>Frequency Band
<select name="a4">
<option value="C-Band">C-Band</option>
<option value="Ku-Band">Ku-Band</option>
</select>
</p></td>
</tr>
<tr>
<td height="53"><p>Transponder
<select name="a5">
<option value="1E">1E</option>
<option value="2E">2E</option>
<option value="3E">3E</option>
<option value="4E">4E</option>
<option value="5E">5E</option>
<option value="6E">6E</option>
<option value="1G">1G</option>
<option value="2G">2G</option>
<option value="3G">3G</option>
<option value="4G">4G</option>
<option value="5G">5G</option>
<option value="6G">6G</option>
<option value="7G">7G</option>
<option value="1V">1V</option>
<option value="2V">2V</option>
<option value="3V">3V</option>
<option value="4V">4V</option>
<option value="5V">5V</option>
<option value="6V">6V</option>
<option value="7V">7V</option>
<option value="8V">8V</option>
<option value="9V">9V</option>
<option value="10V">10V</option>
<option value="11V">11V</option>
<option value="12V">12V</option>
<option value="1H Ku">1H Ku</option>
<option value="2H Ku">2H Ku</option>
<option value="3H Ku">3H Ku</option>
<option value="4H Ku">4H Ku</option>
<option value="5H Ku">5H Ku</option>
<option value="6H Ku">6H Ku</option>
<option value="7H Ku">7H Ku</option>
<option value="8H Ku">8H Ku</option>
<option value="9H Ku">9H Ku</option>
<option value="10H Ku">10H Ku</option>
<option value="11H Ku">11H Ku</option>
<option value="12H Ku">12H Ku</option>
<option value="8V Ku">8V Ku</option>
<option value="9V Ku">9V Ku</option>
<option value="10V Ku">10V Ku</option>
<option value="11V Ku">11V Ku</option>
<option value="12V Ku">12V Ku</option>
</select>
</p>
<p> <input type="submit" name="Submit" value="confirm"></p>
</td>
</tr>
</table>
</div>
</form>
</body>
</html>
<<<<< edit_done>>>>>>>>>>
Code (ASP)
<html>
<!--#include file="conndb.inc"-->
<form name="test1" method="post" action="edit.asp">
<head>
<title>edit done</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<%
sql="UPDATE TCNS_TVRO set(TV_ID,IRD_No,Satellite,Antenna_Size,Polarization,Frequency_Band,Transponder) where('"&request.form("id")&"','"&request.form("IRD_No")&"','"&request.form("a1")&"','"&request.form("a2")&"','"&request.form("a3")&"','"&request.form("a4")&"','"&request.form("a5")&"')"
conn.execute sql
Response.write("<br>complete")
%>
</body>
</html>
</form>
Tag : ASP, Ms SQL Server 2008, VBScript
Date :
2011-05-10 10:31:31
By :
dinu
View :
1555
Reply :
2
ตัวอย่างการแก้ไขครับ ASP + SQL Server
Code (ASP)
<% Option Explicit %>
<html>
<head>
<title>ThaiCreate.Com ASP & SQL Server Tutorial</title>
</head>
<body>
<form action="ASPSQLServerEditRecordSave.asp?CusID=<%=Request.QueryString("CusID")%>" name="frmEdit" method="post">
<%
Dim Conn,strSQL,objRec
Set Conn = Server.Createobject("ADODB.Connection")
Conn.Open "Driver={SQL Server};Server=localhost;Database=mydatabase;UID=sa;PWD=;"
strSQL = "SELECT * FROM customer WHERE CustomerID = '"&Request.QueryString("CusID")&"' "
Set objRec = Conn.Execute(strSQL)
If objRec.EOF Then
Response.write("Not found CustomerID="&Request.QueryString("CusID"))
Else
%>
<table width="600" border="1">
<tr>
<th width="91"> <div align="center">CustomerID </div></th>
<th width="160"> <div align="center">Name </div></th>
<th width="198"> <div align="center">Email </div></th>
<th width="97"> <div align="center">CountryCode </div></th>
<th width="70"> <div align="center">Budget </div></th>
<th width="70"> <div align="center">Used </div></th>
</tr>
<tr>
<td><div align="center"><input type="text" name="txtCustomerID" size="5" value="<%=objRec.Fields("CustomerID")%>"></div></td>
<td><input type="text" name="txtName" size="20" value="<%=objRec.Fields("Name")%>"></td>
<td><input type="text" name="txtEmail" size="20" value="<%=objRec.Fields("Email")%>"></td>
<td><div align="center"><input type="text" name="txtCountryCode" size="2" value="<%=objRec.Fields("CountryCode")%>"></div></td>
<td align="right"><input type="text" name="txtBudget" size="5" value="<%=objRec.Fields("Budget")%>"></td>
<td align="right"><input type="text" name="txtUsed" size="5" value="<%=objRec.Fields("Used")%>"></td>
</tr>
</table>
<input type="submit" name="submit" value="submit">
<%
End IF
objRec.Close()
Conn.Close()
Set objRec = Nothing
Set Conn = Nothing
%>
</form>
</body>
</html>
Go to : ASP SQL Server Edit/Update Record
Date :
2011-05-10 10:39:03
By :
webmaster
<html>
<!--#include file="conndb.inc"-->
<head>
<title>EDIT</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<form name="test1" method="post" action="edit_done.asp">
<%
Dim strSQL,objRec
strSQL = "SELECT * FROM TCNS_TVRO WHERE TV_ID = '"&Request.QueryString("id")&"' "
Set objRec = Server.CreateObject("ADODB.Recordset")
objRec.Open strSQL, conn
If objRec.EOF Then
Response.write("Not found TV_ID="&Request.QueryString("id"))
Else
%>
<div align="center">
<p><strong>EDIT</strong></p>
<table width="733" border="1">
<!--DWLayoutTable-->
<tr>
<td width="723"><p>TV_ID
<input name="id" type="text" id="id" value="<%=objRec.Fields("TV_ID")%>">
</p></td>
</tr>
<tr>
<td><p>IRD_No.
<input name="IRD_No" type="text" id="IRD_No" >
</p></td>
</tr>
<tr>
<td><p>Satellite
<select name="a1">
<option value="Thaicom 4">Thaicom 4</option>
<option value="Thaicom 5">Thaicom 5</option>
<option value="NSS6">NSS6</option>
</select>
</p>
</td>
</tr>
<tr>
<td><p>Antenna Size
<select name="a2">
<option value="60 cm.">60 cm.</option>
<option value="75 cm.">75 cm.</option>
<option value="1.2 m.">1.2 m.</option>
<option value="1.5 m.">1.5 m.</option>
<option value="1.7 m.">1.7 m.</option>
<option value="3 m.">3 m.</option>
</select>
</p></td>
</tr>
<tr>
<td><p>Polarization
<select name="a3">
<option value="Vertical">Vertical</option>
<option value="Horizontal">Horizontal</option>
</select>
</p></td>
</tr>
<tr>
<td><p>Frequency Band
<select name="a4">
<option value="C-Band">C-Band</option>
<option value="Ku-Band">Ku-Band</option>
</select>
</p></td>
</tr>
<tr>
<td height="53"><p>Transponder
<select name="a5">
<option value="1E">1E</option>
<option value="2E">2E</option>
<option value="3E">3E</option>
<option value="4E">4E</option>
<option value="5E">5E</option>
<option value="6E">6E</option>
<option value="1G">1G</option>
<option value="2G">2G</option>
<option value="3G">3G</option>
<option value="4G">4G</option>
<option value="5G">5G</option>
<option value="6G">6G</option>
<option value="7G">7G</option>
<option value="1V">1V</option>
<option value="2V">2V</option>
<option value="3V">3V</option>
<option value="4V">4V</option>
<option value="5V">5V</option>
<option value="6V">6V</option>
<option value="7V">7V</option>
<option value="8V">8V</option>
<option value="9V">9V</option>
<option value="10V">10V</option>
<option value="11V">11V</option>
<option value="12V">12V</option>
<option value="1H Ku">1H Ku</option>
<option value="2H Ku">2H Ku</option>
<option value="3H Ku">3H Ku</option>
<option value="4H Ku">4H Ku</option>
<option value="5H Ku">5H Ku</option>
<option value="6H Ku">6H Ku</option>
<option value="7H Ku">7H Ku</option>
<option value="8H Ku">8H Ku</option>
<option value="9H Ku">9H Ku</option>
<option value="10H Ku">10H Ku</option>
<option value="11H Ku">11H Ku</option>
<option value="12H Ku">12H Ku</option>
<option value="8V Ku">8V Ku</option>
<option value="9V Ku">9V Ku</option>
<option value="10V Ku">10V Ku</option>
<option value="11V Ku">11V Ku</option>
<option value="12V Ku">12V Ku</option>
</select>
</p>
<p> <input type="submit" name="Submit" value="confirm"></p>
</td>
</tr>
</table>
</div>
<%
end if
objRec.Close()
Set objRec = Nothing
Set Conn = Nothing
%>
</form>
</body>
</html>
คือว่าตอนนี้แก้โค้ดเป็นอย่างนี้แล้วค่ะ แต่ว่าพอลองรันดู ปรากฎว่าขึ้นว่า Not found TV_ID= อะค่ะ ทั้งๆที่ตอนนี้มีข้อมูลอยู่ในฐานข้อมูลแล้วค่ะ รบกวนช่วยดูให้หน่อยนะคะ ขอบคุณค่ะ
Date :
2011-05-10 11:58:30
By :
dinu
Load balance : Server 05