本文介绍了如何从数据库自动计算?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
您好。
我正在尝试从数据库中自动计算。我所拥有的是TextBox1,TextBox2和TextBox3。我正在从数据库填充TextBox1和TextBox2,我在Textbox2上有TextBox_Text更改。如何从文件夹中获取两个TextBox来计算数字?这是我的代码。我在TextBox2上也有AutoPostBack。
Hello.
I am trying to auto calculate from the database. What I have is TextBox1, TextBox2 and TextBox3. I am populating TextBox1 and TextBox2 from the database and I have the TextBox_Text change on Textbox2. How can I get the two TextBoxes to calculate the numbers from the database? This is the code I have in place. I also have AutoPostBack on TextBox2.
using System;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Text;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Configuration;
using System.Drawing.Printing;
using System.IO;
using System.Web.SessionState;
using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.Shared;
namespace SACSCOCLogin1._1
{
public partial class TestCal : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["HotConnectionString"].ConnectionString);
con.Open();
SqlCommand scmd = new SqlCommand("Select Cars, Trucks from TestCal", con);
SqlDataReader dr = scmd.ExecuteReader();
if (dr.Read())
{
TextBox1.Text = dr["Cars"].ToString();
TextBox2.Text = dr["Trucks"].ToString();
}
dr.Close();
con.Close();
}
protected void TextBox1_TextChanged(object sender, EventArgs e)
{
int a = Convert.ToInt32(TextBox1.Text);
int b = Convert.ToInt32(TextBox2.Text);
TextBox3.Text = Convert.ToString(a + b);
}
}
}
推荐答案
using System;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Text;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Configuration;
using System.Drawing.Printing;
using System.IO;
using System.Web.SessionState;
using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.Shared;
namespace SACSCOCLogin1._1
{
public partial class TestCal : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["HotConnectionString"].ConnectionString);
con.Open();
SqlCommand scmd = new SqlCommand("Select Cars, Trucks from TestCal", con);
SqlDataReader dr = scmd.ExecuteReader();
if (dr.Read())
{
TextBox1.Text = dr["Cars"].ToString();
TextBox2.Text = dr["Trucks"].ToString();
}
dr.Close();
con.Close();
{
int a = Convert.ToInt32(TextBox1.Text);
int b = Convert.ToInt32(TextBox2.Text);
TextBox3.Text = Convert.ToString(a + b);
}
}
}
}
这篇关于如何从数据库自动计算?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!