private void Page_Load(object sender, System.EventArgs e)
{
SqlConnection conn=new SqlConnection(System.Configuration.ConfigurationSettings.AppSettings["SQL_Connection"]);
string classid;
string sqlstr="select * from table1 where parentid =0";
conn.Open();
SqlCommand comm=new SqlCommand(sqlstr,conn);
SqlDataReader dr=comm.ExecuteReader();
while (dr.Read())
{
Response.Write(dr["classname"].ToString()+"<br>");
GetType(dr["classid"].ToString());
}
conn.Close();
} public void GetType(string parentid)
{
if (parentid!="0")
{
SqlConnection conn1=new SqlConnection(System.Configuration.ConfigurationSettings.AppSettings["SQL_Connection"]);
conn1.Open();
string sqlstr="select * from table1 where classid="+parentid;
SqlCommand comm1=new SqlCommand(sqlstr,conn1);
comm1.Connection=conn1;
comm1=new SqlCommand(sqlstr);
SqlDataReader dr1=comm1.ExecuteReader();
while(dr1.Read())
{
Response.Write(dr1["classname"].ToString()+"<br>");
}
conn1.Close();
}
}
--------------------------
为什么一运行程序就失败
ExecuteReader: Connection 属性尚未初始化。
{
SqlConnection conn=new SqlConnection(System.Configuration.ConfigurationSettings.AppSettings["SQL_Connection"]);
string classid;
string sqlstr="select * from table1 where parentid =0";
conn.Open();
SqlCommand comm=new SqlCommand(sqlstr,conn);
SqlDataReader dr=comm.ExecuteReader();
while (dr.Read())
{
Response.Write(dr["classname"].ToString()+"<br>");
GetType(dr["classid"].ToString());
}
conn.Close();
} public void GetType(string parentid)
{
if (parentid!="0")
{
SqlConnection conn1=new SqlConnection(System.Configuration.ConfigurationSettings.AppSettings["SQL_Connection"]);
conn1.Open();
string sqlstr="select * from table1 where classid="+parentid;
SqlCommand comm1=new SqlCommand(sqlstr,conn1);
comm1.Connection=conn1;
comm1=new SqlCommand(sqlstr);
SqlDataReader dr1=comm1.ExecuteReader();
while(dr1.Read())
{
Response.Write(dr1["classname"].ToString()+"<br>");
}
conn1.Close();
}
}
--------------------------
为什么一运行程序就失败
ExecuteReader: Connection 属性尚未初始化。
解决方案 »
- 网站被上传了churrasco.exe这个文件,哪位知道可能的漏洞是什么
- 怎样去掉字符串左边的0(急)
- ★★各位帮忙看看这个删除功能怎么实现★★
- 高分求救,遇到了难题,请问如何解决?关于Asp.net 3.5的问题
- 请问DropDownList的值是否可以直接用RequiredFieldValidator来验证
- 疑问! 如果自定义控件中有一个属性是 String[] 字符串集合类型,那么我们在属性浏览窗口,给它赋值时,为什么不行??是不是自己要写类
- 验证控件的问题
- 问兄弟们一个数据库连接的问题,谢了!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!111
- 读取XML的问题,急,进来看看,在线等
- 简单问题,在线等待,急!
- 我们在做一个系统,每一年有500多项方案是用word文档做的。我想请教大家这些方案是上传到SQL SERVER还是上传到服务器文件夹好?
- 马上结贴的问题。。。
大哥 COMM是什么东东啊 你看清楚
comm1.Connection=conn1;
comm1=new SqlCommand(sqlstr)
这里好像有问题啊
之后没有关conn
然后GetType中你又打开了一次