打开窗体设计器看有没有多的SqlDataReader
解决方案 »
- 用C#怎么向Excel表格中插入压缩文件
- pParm[0] = new OracleParameter("BUREAUID", OracleDbType.Varchar2)这句话错在哪
- svhost.exe中出现未处理的Win32异常
- winForm中打开另一个winForm的问题
- c# 程序bs结构的,想在没有鼠标的情况下想按enter键依次实现输入信息。
- C# winform以远程mysql作为数据库,mysql编码utf8,C#中的sql语句不能带中文,怎么解决啊?
- 提一个面向对象的问题~~~
- 求求各位大虾,帮我这段代码注释一下再详细点,谢了。
- C#中如何使用进度条?
- 错误:重载“XmlTextReader”方法未获取“1”参数,请问需要什么参数?
- ··DataGrid1_ItemCommand需要实现下载功能,命令没有错误,为什么无法触发ItemCommand事件??点击按钮后没有任何反应。有代码,在线等
- 怎样把DataSet分成几个DataSet
SqlConnection.close();
SqlDataReader
看它的具体 实例是什么
没有关闭的 Close()
{
string selectSqlString = "SELECT * FROM ClassList WHERE (Parent=0) ORDER BY Parent";
try
{
con = new SqlConnection(ConString);
cmd = new SqlCommand(selectSqlString,con);
con.Open();
dr = cmd.ExecuteReader();
while(dr.Read())
{
CheckBox cb = new CheckBox();
cb.ID = dr["Id"].ToString();
cb.Text = dr["Title"].ToString();
this.Panel1.Controls.Add(cb);
}
}
catch(Exception ex)
{
Response.Write(ex.ToString());
}
finally
{
dr.Close();//释放
cmd.Dispose();
con.Close();
}
}
SqlDataReader.Dispose()
SqlConnection.close();
是对的,希望楼主mm留意要优化代码就
一般不会用到
SqlDataReader.close();
SqlDataReader.Dispose()
这个就好了!
SqlConnection.close();
{
string selectSqlString = "SELECT * FROM ClassList WHERE (Parent=0) ORDER BY Parent";
try
{
con = new SqlConnection(ConString);
cmd = new SqlCommand(selectSqlString,con);
con.Open();
dr = cmd.ExecuteReader();
while(dr.Read())
{
CheckBox cb = new CheckBox();
cb.ID = dr["Id"].ToString();
cb.Text = dr["Title"].ToString();
this.Panel1.Controls.Add(cb);
}
}
catch(Exception ex)
{
Response.Write(ex.ToString());
}
finally
{
dr.Close();//释放
cmd.Dispose();
con.Close();
}
}
SqlDataReader.close();
SqlConnection.close();
/// <summary>
/// 删除附件ID
/// </summary>
/// <param name="attachmentID">要删除的附件ID</param>
public void DeleteAttachment(int attachmentID)//ICSharp_DeleteAttachment
{
SqlConnection conn = new SqlConnection(PortalSettings.SqlConnectionString);
SqlCommand comm = new SqlCommand("ICSharp_DeleteAttachment",conn);
comm.CommandType = CommandType.StoredProcedure;
SqlParameter param = comm.Parameters.Add(new SqlParameter("@AttachmentID",SqlDbType.Int));
comm.Parameters[0].Value = attachmentID; try
{
conn.Open();
comm.ExecuteNonQuery();
}
catch(Exception ex)
{
throw new Exception("",ex);
}
finally
{
if(conn.State != ConnectionState.Closed)
conn.Close();
}
}
SqlConnection.close();
必须写这两句才可以再次打开连接
{
//... 你的应用逻辑
}
用毕,会自动释放资源
SqlDataReader.Dispose();释放
SqlConnection.close();关闭联接