C# 编译时出现——当前上下文中不存在名称 textBox1 ?这个怎么修改?照着书打的,应该没错啊。。。
usingSystem;usingSystem.Collections.Generic;usingSystem.ComponentModel;usingSystem.Da...
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace 消费管理系统
{
public partial class Form3 : Form
{
public Form3()
{
InitializeComponent();
}
private void 查询_Click(object sender, EventArgs e)
{
}
private void label1_Click(object sender, EventArgs e)
{
}
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
}
private void 消费项目信息查询界面_Load(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection("server=(local);user id=myzf;pwd=123456;database=DataServer");
con.Open();
SqlCommand com=new SqlCommand("select distinct(spendprocd) from consume",con);
SqlDataReader dr=com.ExecuteReader();
comboBox1.Items.Clear();
while(dr.Read())
{
comboBox1.Items.Add(dr[0].ToString());
}
dr.Close();
con.Close();
}
private void button1_Click(object sender, EventArgs e)
{
string ConStr="server=(local);user id=myzf;pwd=123456;database=DataServer";
SqlConnection con = new SqlConnection(ConStr);
string SqlStr = "select spendprocd as 消费项目,spendMoney as 消费金额,spendDate as 消费日期 from consume where spendprocd='"+comboBox1.SelectedItem.ToString()+"'";
SqlDataAdapter ada=new SqlDataAdapter(SqlStr,con);
DataSet ds=new DataSet();
ada.Fill(ds);
this.dataGridView1.DataSource=ds.Tables[0].DefaultView;
con.Close();
SqlConnection mycon=new SqlConnection("server=(local);user id=myzf;pwd=123456;database=DataServer");
mycon.Open();
SqlCommand cmd = new SqlCommand("select sum(spendMoney) from consume where spendprocd='" + comboBox1.SelectedItem.ToString() + "'", mycon);
SqlDataReader drr=cmd.ExecuteReader();
while(drr.Read())
{
textBox1.Text = String.Format(Convert.ToDouble(drr.GetValue(0)).ToString());
textBox1.BackColor = Color.GreenYellow;
}
}
}
} 展开
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace 消费管理系统
{
public partial class Form3 : Form
{
public Form3()
{
InitializeComponent();
}
private void 查询_Click(object sender, EventArgs e)
{
}
private void label1_Click(object sender, EventArgs e)
{
}
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
}
private void 消费项目信息查询界面_Load(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection("server=(local);user id=myzf;pwd=123456;database=DataServer");
con.Open();
SqlCommand com=new SqlCommand("select distinct(spendprocd) from consume",con);
SqlDataReader dr=com.ExecuteReader();
comboBox1.Items.Clear();
while(dr.Read())
{
comboBox1.Items.Add(dr[0].ToString());
}
dr.Close();
con.Close();
}
private void button1_Click(object sender, EventArgs e)
{
string ConStr="server=(local);user id=myzf;pwd=123456;database=DataServer";
SqlConnection con = new SqlConnection(ConStr);
string SqlStr = "select spendprocd as 消费项目,spendMoney as 消费金额,spendDate as 消费日期 from consume where spendprocd='"+comboBox1.SelectedItem.ToString()+"'";
SqlDataAdapter ada=new SqlDataAdapter(SqlStr,con);
DataSet ds=new DataSet();
ada.Fill(ds);
this.dataGridView1.DataSource=ds.Tables[0].DefaultView;
con.Close();
SqlConnection mycon=new SqlConnection("server=(local);user id=myzf;pwd=123456;database=DataServer");
mycon.Open();
SqlCommand cmd = new SqlCommand("select sum(spendMoney) from consume where spendprocd='" + comboBox1.SelectedItem.ToString() + "'", mycon);
SqlDataReader drr=cmd.ExecuteReader();
while(drr.Read())
{
textBox1.Text = String.Format(Convert.ToDouble(drr.GetValue(0)).ToString());
textBox1.BackColor = Color.GreenYellow;
}
}
}
} 展开
展开全部
你的form里没有textBox这个控件,添加一个textBox控件就好了
更多追问追答
追问
怎么添加?具体的~
追答
直接往窗体上拖就行啊
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
你有在视图设计窗口添加textBox1吗?
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询