 |
|
รบกวนถามเรื่องการคำนวณข้อมูลใน Field หน่อยค่ะ เช่นเรามี ฟิลด์ข้อมูล Class ใน table student แล้วเราต้องการคำนวณ |
|
 |
|
|
 |
 |
|
select count(*) as amount_student,max(score) as max_score,min(score) as min_score,avg(score) as avg_score
from student
where class = 'A'
|
 |
 |
 |
 |
Date :
1 ก.ย. 2549 09:45:33 |
By :
มักกะโรนีกะหมากเก็บ |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ขอบคุณ คุณมักกะโรนีกะหมากเก็บมากค่ะ รบกวนถามอีกนิดได้มั้ยอะคะ แล้วเวลาเราจะเขียน ASP ให้แสดงผลลัพธ์นี่เราจะต้องทำยังงัยอะคะ รบกวนหน่อยนะคะ 
|
 |
 |
 |
 |
Date :
1 ก.ย. 2549 12:13:50 |
By :
แอม |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
คือว่าแอมเขียนแบบนี้น่ะค่ะ มีการรับค่า oprion1 (ซึ่งก็คือชื่อ class) มาจาก form
<%
option1=request.Form("option1")
set objConn = Server.CreateObject("ADODB.Connection")
objConn.Open "Driver={Microsoft Access Driver (*.mdb)};DBQ="& Server.MapPath("eis.mdb")
csql = "select count(*) as amount_student,max(score) as max_score,min(score) as min_score,avg(score)as avg_score from student where class = 'option1' "
Set objRs = Server.CreateObject("ADODB.Recordset")
objRs.open csql, objConn, 0, 3
%>
แล้วทีนี้ มัน error ว่าแบบนี้อะค่ะ
Error Type:
Microsoft OLE DB Provider for ODBC Drivers (0x80040E10)
[Microsoft][ODBC Microsoft Access Driver] Too few parameters. Expected 1.
ในบรรทัด -->objRs.open csql, objConn, 0, 3 นี้น่ะค่ะ
แก้ไม่ถูกเลย แล้วก็เวลาเราจะแสดงค่านี้ใช้ ฟังก์ชั่นยังงัยอะคะ รบกวนหน่อยนะคะ

|
 |
 |
 |
 |
Date :
1 ก.ย. 2549 12:21:39 |
By :
แอม |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
csql = "select count(*) as amount_student,max(score) as max_score,min(score) as min_score,avg(score)as avg_score from student where class = 'option1' "
จากข้างบนนะคะ error น่าจะมาจากตรงเงื่อนไข where น่ะค่ะ เพราะว่า option1 เป็นตัวแปร ดังนั้นเราต้องใช้ว่า
csql = "select count(*) as amount_student,max(score) as max_score,min(score) as min_score,avg(score)as avg_score from student where class = '"&option1&"'"
|
 |
 |
 |
 |
Date :
1 ก.ย. 2549 13:03:23 |
By :
มักกะโรนีกะหมากเก็บ |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ไม่ error แล้วค่ะ ขอบคุณ คุณมักกะโรนีกะหมากเก็บมากนะคะ นั่งมึนอยู่ตั้ง 4 วันแล้ว ขอบคุณจิงๆค่ะ
|
 |
 |
 |
 |
Date :
1 ก.ย. 2549 13:53:48 |
By :
แอม |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|