我试图在 ASPX 页面上显示下面的查询值(总计),但我一直得到 0。当我输入断点并调试时,总计都应该等于 15.0。该值在从中提取的 MS SQL 数据库中保存为小数。
.cs 页面
public partial class Payment : System.Web.UI.Page
{
public double total;
protected void Page_Load(object sender, EventArgs e)
{
var id = Request.Params["ID"];
System.Data.OleDb.OleDbConnection conn;
System.Data.OleDb.OleDbCommand cmd;
conn = new System.Data.OleDb.OleDbConnection("--");
cmd = new System.Data.OleDb.OleDbCommand();
conn.Open();
cmd.Connection = conn;
var sql = String.Format(@"select sum(PayAmt) as total from CurePay where CureID = '{0}'", id);
cmd.CommandText = sql;
double total = 0;
total = Convert.ToDouble(cmd.ExecuteScalar());
conn.Close();
.ASPX 页面
<%= total %>