strSQL = "SELECT BloodGroup,SUM(Quantity) FROM CallEmerge GROUP BY BloodGroup"
แต่มันขึ้น error ว่า
Quantity is neither a DataColumn nor a DataRelation for table Table.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.ArgumentException: Quantity is neither a DataColumn nor a DataRelation for table Table.
คือถ้าลองใช้ strSQL = "SELECT BloodGroup,Quantity FROM CallEmerge "
มันก้อดึงได้ปกติ คงน่าจะมีปัญหาเกี่ยวกับ Group by sum จะแก้ปัญหานี้อย่างไรดีค่ะ
<%@ Import Namespace="System.Data"%>
<%@ Import Namespace="System.Data.SqlClient"%>
<%@Import Namespace="System.IO" %>
<%@ Page Language="VB" %>
<%@ Register Assembly="System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
Namespace="System.Web.UI" TagPrefix="asp" %>
<script runat="server">
Dim objConn As SqlConnection
Dim objCmd As SqlCommand
Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
Dim strConnString As String
strConnString = "Server=localhost;UID=sa;PASSWORD=xxxx;database=blooddb;Max Pool Size=400;Connect Timeout=600;"
objConn = New SqlConnection(strConnString)
objConn.Open()
BindData()
Label2.Text = "Last update :" + " " + DateTime.Now.ToString()
End Sub
Sub IntervalTimer_Tick(ByVal sender As Object, ByVal e As EventArgs) Handles IntervalTimer.Tick
Label2.Text = "Last update :" + " " + DateTime.Now.ToString()
BindData()
End Sub
Sub BindData()
Dim ds As DataSet
ds = CreateDataSet()
myRepeater.DataSource = ds.Tables(0).DefaultView
myRepeater.DataBind()
End Sub
Function CreateDataSet() As DataSet
Dim objConn As New System.Data.SqlClient.SqlConnection
Dim objCmd As New System.Data.SqlClient.SqlCommand
Dim dtAdapter As New System.Data.SqlClient.SqlDataAdapter
Dim wr As StreamWriter = File.CreateText(Server.MapPath("computeblood.xml"))
Dim ds As New DataSet
Dim strConnString,strSQL As String
strConnString = "Server=localhost;UID=sa;PASSWORD=xxxx;database=blooddb;Max Pool Size=400;Connect Timeout=1000;"
strSQL = "SELECT BloodGroup,SUM(Quantity) FROM CallEmerge GROUP BY BloodGroup"
objConn.ConnectionString = strConnString
With objCmd
.Connection = objConn
.CommandText = strSQL
.CommandType = CommandType.Text
End With
dtAdapter.SelectCommand = objCmd
dtAdapter.Fill(ds)
'***ds.WriteXml(Server.MapPath("computeblood.xml"))***'
ds.WriteXml(wr)
wr.Close()
dtAdapter = Nothing
objConn.Close()
objConn = Nothing
Return ds '*** Return DataSet ***'
End Function
</script>