为什么这一段程序显示的异常是:
未将对象引用设置到对象的实例啊?
foreach ( DataRow adc in dataset.Tables["feemanage"].Rows)
{
income1+=float.Parse(adc["income"].ToString());
}
MessageBox.Show(income1.ToString());
我在控制台里面这一段程序根本没有错的 可是在 window 下就出现异常
异常就是
未将对象引用设置到对象的实例啊?以下是我的代码 谢谢
try
{
OleDbConnection connection =
new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;
Data Source=
C:\Documents and Settings\Administrator\桌面\班费管理模块\feemanage.mdb");
//连接数据库;声明数据源
connection.Open();//打开数据库
string tex =textBox1.Text;
string sql = "SELECT * FROM feemanage WHERE time <=# " + tex + "#" ;
//
//
OleDbDataAdapter adapter = new OleDbDataAdapter( sql ,connection );
OleDbCommandBuilder builder = new OleDbCommandBuilder (adapter);
DataSet dataset = new DataSet();
adapter.Fill ( dataset,"feemanage " );
float income1 = 0;//算出整的收入
float expense1 =0;//算出整的支出
foreach ( DataRow adc in dataset.Tables["feemanage"].Rows)
{
income1+=float.Parse(adc["income"].ToString());
}
MessageBox.Show(income1.ToString());
foreach ( DataRow adc in dataset.Tables["feemanage"].Rows)
{
expense1+=float.Parse(adc["expense"].ToString());
}
float jieyu=income1-expense1;
MessageBox.Show(jieyu.ToString());
connection.Close();
jieyu1.Show();//显示窗体
jieyu1.Activate();//激活窗体给予焦点
jieyu1.textBoxjia.Text=jieyu.ToString();
connection.Close();
}
catch ( Exception ex)
{
MessageBox.Show(ex.Message);
}
}