asp.net 运行出现System.NullReferenceException: 未将对象引用设置到对象的实例。但我看到我以下的代码没看到有引用或对象实例没对照啊 帮忙看下using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
public partial class repaire_insert : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{ }
protected void Button1_Click(object sender, EventArgs e)
{
float f=0.0F;
float f1=0.0F;
float f2=0.0F;
float f3=0.0F;
SqlConnection myConnection=new SqlConnection (System.Configuration .ConfigurationSettings .AppSettings ["connString"]);
myConnection .Open ();
string[] str1 = TextBox3.Text.Split(new char[] { ',' });//取出所用到的材料名称以,区分开来
string[] str2= TextBox4.Text.Split(new char[] { ',' });//取出对应的用材料的数量
//材料费
for(int i=0;i<str1 .Length ;i++)
{
string queryStr="select 单位价格 from 材料表 where 材料名称='str1[i]'";
SqlCommand myCommand1=new SqlCommand (queryStr ,myConnection );
f=float .Parse (myCommand1 .ExecuteScalar().ToString ());
f1=f*float .Parse (str2[i])+f1;
}
//劳务费
string queryStr1="select 单位时间费用 from 劳务表 where 项目名称='"+TextBox6 .Text +"'";
SqlCommand myCommand2=new SqlCommand (queryStr1 ,myConnection );
f2 =float.Parse (myCommand2 .ExecuteScalar ().ToString ());
f3 =f2 * float.Parse (TextBox5 .Text );
string insertStr="insert into 房屋修缮表 (业主房号,签收人姓名,用料数量,用料名称,花费时间,项目名称,材料费,劳务费,总计费用,日期) values ('"+TextBox1 .Text +"','"+TextBox2 .Text +"','"+TextBox3 .Text +"','"+TextBox4 .Text +"',"+TextBox5 .Text +",'"+TextBox6 .Text +"',f1,f3,f1+f3,getdate())";
SqlCommand myCommand=new SqlCommand (insertStr ,myConnection ); try
{
myCommand .ExecuteNonQuery ();
}
catch
{
Label1 .Text ="fail";
}
finally
{
myConnection .Close ();
}
}
}
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
public partial class repaire_insert : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{ }
protected void Button1_Click(object sender, EventArgs e)
{
float f=0.0F;
float f1=0.0F;
float f2=0.0F;
float f3=0.0F;
SqlConnection myConnection=new SqlConnection (System.Configuration .ConfigurationSettings .AppSettings ["connString"]);
myConnection .Open ();
string[] str1 = TextBox3.Text.Split(new char[] { ',' });//取出所用到的材料名称以,区分开来
string[] str2= TextBox4.Text.Split(new char[] { ',' });//取出对应的用材料的数量
//材料费
for(int i=0;i<str1 .Length ;i++)
{
string queryStr="select 单位价格 from 材料表 where 材料名称='str1[i]'";
SqlCommand myCommand1=new SqlCommand (queryStr ,myConnection );
f=float .Parse (myCommand1 .ExecuteScalar().ToString ());
f1=f*float .Parse (str2[i])+f1;
}
//劳务费
string queryStr1="select 单位时间费用 from 劳务表 where 项目名称='"+TextBox6 .Text +"'";
SqlCommand myCommand2=new SqlCommand (queryStr1 ,myConnection );
f2 =float.Parse (myCommand2 .ExecuteScalar ().ToString ());
f3 =f2 * float.Parse (TextBox5 .Text );
string insertStr="insert into 房屋修缮表 (业主房号,签收人姓名,用料数量,用料名称,花费时间,项目名称,材料费,劳务费,总计费用,日期) values ('"+TextBox1 .Text +"','"+TextBox2 .Text +"','"+TextBox3 .Text +"','"+TextBox4 .Text +"',"+TextBox5 .Text +",'"+TextBox6 .Text +"',f1,f3,f1+f3,getdate())";
SqlCommand myCommand=new SqlCommand (insertStr ,myConnection ); try
{
myCommand .ExecuteNonQuery ();
}
catch
{
Label1 .Text ="fail";
}
finally
{
myConnection .Close ();
}
}
}
解决方案 »
- 关于模板引擎的问题。。。。。求助阿。
- js自增table行 填入数据库问题
- forms验证,退出登录后 点击后退按钮 仍然可以看到登录后的内容,该如何避免.
- asp.net 多线程问题
- 中文操作系统如何转换日期得到英文月分?
- 如何判断从数据库里查询出来的2列内容是同一行的
- cs+bs模式如何实现?
- ASP.NET中DataBinder中的引号问题,请人指导!
- 我的系统是2003,今天从网上下载一个ASP.NET程序,一执行添加一条记录就出现出错!!!郁闷
- asp.net mvc 4 使用ScriptBundle打包JS文件问题。无法引用js文件
- 如何保持属性值?
- 系统提示"长度不能为0,参数名length"
里是否有数据。
比如:Arraylist a=null;
a.Add();
此时便会报错,未将对象引用到对象的实例,因为 a为空啊
string[] str1 = TextBox3.Text.Split(new char[] { ',' });//取出所用到的材料名称以,区分开来 string[] str2= TextBox4.Text.Split(new char[] { ',' });//取出对应的用材料的数量 //材料费 for(int i=0;i <str1 .Length ;i++)
{
string queryStr="select 单位价格 from 材料表 where 材料名称='str1[i]'";
SqlCommand myCommand1=new SqlCommand (queryStr ,myConnection );
f=float .Parse (myCommand1.ExecuteScalar() == null ? "0" :myCommand1 .ExecuteScalar().ToString ());
f1=f*float .Parse (str2[i])+f1;
}