触摸芯片多少钱一个:有个关于hashtable的 问题 C#
来源:百度文库 编辑:神马品牌网 时间:2024/04/29 15:11:55
private void Page_Load(object sender, System.EventArgs e)
{
Hashtable ht=new Hashtable();
ht.Add(9,1);
ht.Add(8,3);
string temp="(";
foreach(int str in ht.Keys)
{
temp=temp+str.ToString() + ",";
}
temp=temp.Substring(0,temp.Length-1);
temp+=")";
SqlConnection scon=new SqlConnection(System.Configuration.ConfigurationSettings.AppSettings["con"]);
scon.Open();
DataTable table1=new DataTable();
DataSet ds=new DataSet();
SqlDataAdapter sda=new SqlDataAdapter();
sda.SelectCommand=new SqlCommand("select * from thing where thingID in"+temp,scon);
sda.Fill(ds,"product");
table1=ds.Tables["product"];
table1.Columns.Add(new DataColumn("pty",typeof(int)));
//
DataColumn[] key ={table1.Columns["thingName"]};
table1.PrimaryKey=key;
foreach(int str in ht.Keys)
{
table1.Rows.Find(str)["pty"]=ht[str].ToString();
}
this.DataGrid1.DataSource=ds.Tables["product"];
//table1.DefaultView;
this.DataGrid1.DataSource=new DataView(table1);
this.DataGrid1.DataBind();
scon.Close();
}
大概意思是说将 hashtable内的东西 加如数据视图。
但是出错
只是说
未将对象引用设置到对象的实例。
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。
异常详细信息: System.NullReferenceException: 未将对象引用设置到对象的实例。
请问怎么解决 谢谢
{
Hashtable ht=new Hashtable();
ht.Add(9,1);
ht.Add(8,3);
string temp="(";
foreach(int str in ht.Keys)
{
temp=temp+str.ToString() + ",";
}
temp=temp.Substring(0,temp.Length-1);
temp+=")";
SqlConnection scon=new SqlConnection(System.Configuration.ConfigurationSettings.AppSettings["con"]);
scon.Open();
DataTable table1=new DataTable();
DataSet ds=new DataSet();
SqlDataAdapter sda=new SqlDataAdapter();
sda.SelectCommand=new SqlCommand("select * from thing where thingID in"+temp,scon);
sda.Fill(ds,"product");
table1=ds.Tables["product"];
table1.Columns.Add(new DataColumn("pty",typeof(int)));
//
DataColumn[] key ={table1.Columns["thingName"]};
table1.PrimaryKey=key;
foreach(int str in ht.Keys)
{
table1.Rows.Find(str)["pty"]=ht[str].ToString();
}
this.DataGrid1.DataSource=ds.Tables["product"];
//table1.DefaultView;
this.DataGrid1.DataSource=new DataView(table1);
this.DataGrid1.DataBind();
scon.Close();
}
大概意思是说将 hashtable内的东西 加如数据视图。
但是出错
只是说
未将对象引用设置到对象的实例。
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。
异常详细信息: System.NullReferenceException: 未将对象引用设置到对象的实例。
请问怎么解决 谢谢