protected void Page_Load(object sender, EventArgs e)
{ if (!this.Page.IsPostBack)
{
string v7;
SqlCommand cmd = new SqlCommand();
SqlConnection con = new SqlConnection("Server=(local);user id=sa;pwd=;database=master");
con.Open();
SqlDataAdapter ap = new SqlDataAdapter("select sum(expend) from account_bill",con);
v7 = ap;
this.label.Text =v7;
con.Close(); }
提示错误: 错误 1 无法将类型“System.Data.SqlClient.SqlDataAdapter”隐式转换为“string”
{ if (!this.Page.IsPostBack)
{
string v7;
SqlCommand cmd = new SqlCommand();
SqlConnection con = new SqlConnection("Server=(local);user id=sa;pwd=;database=master");
con.Open();
SqlDataAdapter ap = new SqlDataAdapter("select sum(expend) from account_bill",con);
v7 = ap;
this.label.Text =v7;
con.Close(); }
提示错误: 错误 1 无法将类型“System.Data.SqlClient.SqlDataAdapter”隐式转换为“string”
SqlCommand cmd = new SqlCommand(); SqlConnection con = new SqlConnection("Server=(local);user id=sa;pwd=;database=master");
con.Open();
SqlDataAdapter ap = new SqlDataAdapter("select sum(expend) from account_bill", con);
DataTable dt = new DataTable();
ap.Fill(dt);
if (dt != null && dt.Rows.Count > 0)
{
v7 = dt.Rows[0][0].ToString();
}
con.Close();
SqlCommand cmd = new SqlCommand(sql, con);
con.Open();
string v7 = cmd.ExecuteScalar();
this.label.Text =v7;
con.Close[/code]
楼主有点复杂化问题了
SqlCommand cmd = new SqlCommand();
SqlConnection con = new SqlConnection("Server=(local);user id=sa;pwd=;database=master");
con.Open();
SqlDataAdapter ap = new SqlDataAdapter("select sum(expend) from account_bill",con);
v7 = ap;
this.label.Text =v7;
con.Close();
这也能赋值?找基础的书看看先吧
{ if (!this.Page.IsPostBack)
{
SqlConnection con = new SqlConnection("Server=(local);user id=sa;pwd=;database=master");
string sql="select sum(expend) from account_bill";
SqlCommand cmd = new SqlCommand(sql,con);
con.Open();
string v7 = cmd.ExecuteScalar();
this.label.Text = v7;
con.Close(); }
}错误 1 无法将类型“object”隐式转换为“string”
非常感谢shadowjl !感谢各位!
{ if (!this.Page.IsPostBack)
{
string v7;
SqlCommand cmd = new SqlCommand();
SqlConnection con = new SqlConnection("Server=(local);user id=sa;pwd=;database=master");
con.Open();
cmd.CommandText="select sum(expend) from account_bill";
cmd.Connection=con;
v7 = cmd.ExecuteScalar().ToString();
this.label.Text =v7;
con.Close(); }