But the amount is not displaying correctlyin my field
VB Code:
<%@ Page Language="C#" Debug="true"%>
<%@ Import Namespace="System.Data"%>
<%@ Import Namespace="System.Data.OleDb"%>
<SCRIPT LANGUAGE="C#" Runat="server">
OleDbCommand cmd;
static String pathinfo="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:/InetPub/wwwroot/database/buyerStats.mdb";
OleDbConnection conn = new OleDbConnection(pathinfo);
int dr;
void Page_Load(object sender, System.EventArgs e)
{
double amount = 0.0;
string cmdText = "select sum ( poamount ) as amount from [stats] where buyer = 'Brad' group by poamount";
using (cmd = new OleDbCommand(cmdText, conn))
{
try
{
cmd.Connection.Open();
object result = cmd.ExecuteScalar();
if (result != null)
{
amount = System.Convert.ToDouble(result);
}
}
finally
{
if (cmd != null && cmd.Connection != null)
{
cmd.Connection.Close();
}
}
}
conn.Close();
}
</SCRIPT>
<html>
<body>
<form runat="server">
Number of Pos:<asp:Literal id="amount" runat="server" />
</form>
</body>
</html>
Is there anyproblem with the following code???
It says The data value could not be converted for reasons other than sign mismatch or data overflow. For example, the data was corrupted in the data store but the row was still retrievable at output[i] = dataRead.GetInt32(0).
VB Code:
<%@ Page Language="C#" Debug="true"%>
<%@ Import Namespace="System.Data"%>
<%@ Import Namespace="System.Data.OleDb"%>
<SCRIPT LANGUAGE="C#" Runat="server">
OleDbCommand cmd;
OleDbDataAdapter da1;
DataSet ds;
static String pathinfo="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:/InetPub/wwwroot/database/buyerStats.mdb";
OleDbConnection conn = new OleDbConnection(pathinfo);
int dr,i=0;
int[] output;
void Page_Load(object sender, System.EventArgs e)
{
double amount = 0.0;
string cmdText = "select sum ( poamount ) as bradAmount from [stats] where buyer = 'Brad' group by Buyer";
cmdText += " UNION select sum( poamount ) as judyAmount from [stats] where buyer = 'Judy' group by Buyer";
cmdText += " UNION select sum( poamount ) as mikeAmount from [stats] where buyer = 'Mike' group by Buyer";
cmdText += " UNION select sum( poamount ) as sueAmount from [stats] where buyer = 'Sue' group by Buyer";
cmdText += " UNION select sum( poamount ) as jeffAmount from [stats] where buyer = 'Jeff' group by Buyer";
OleDbDataReader dataRead;
using (cmd = new OleDbCommand(cmdText, conn))
{
conn.Open();
dataRead = cmd.ExecuteReader();
try
{
while(dataRead.Read())
{
output[i]=dataRead.GetInt32(0);
i++;
}
}
finally
{
if (dataRead != null)
{
dataRead.Close();
}
if (conn.State == ConnectionState.Open)
{
conn.Close();
}
}
}
conn.Close();
}
</SCRIPT>
<html>
<body>
</body>
</html>