数据库连接,帮我看看有什么错

lim62008 2008-06-28 01:19:56

using System;
using System.Collections;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Diagnostics;
using System.ComponentModel;
using System.Collections;


namespace WebSite1.DataAcessLayer
{
public class Database : IDisposable
{
protected SqlConnection Connection;

protected String ConnectionString;

public Database()
{
ConnectionString = ConfigurationSettings.AppSettings["DBConnectionString"];
}

~Database()
{
try
{
if (Connection != null)
{
Connection.Close();
}
}catch { }
try
{
Dispose();

}
catch{ }
}
protected void open()
{
if(Connection == null)
{
Connection = new SqlConnection(ConnectionString);
}
if(Connection.State.Equals(ConnectionState.Closed))
{
Connection.Open();
}
}
public void Close()
{
if (Connection != null)
{
Connection.Close();
}
}
public void Dispose() //释放连接数据库所占用的资源
{
if(Connection !=null)
{
Connection.Dispose();
Connection = null;
}
}
public int ExecuteSQL(String SqlString)
{
int count = -1;
open();
try
{
SqlCommand cmd = new SqlCommand(SqlString, Connection);
count = cmd.ExecuteNonQuery();

}
catch
{
count = -1;

}
finally
{
Close();
}
return count;
}
public DataSet GetDataSet(String SqlString)
{
open();
SqlDataAdapter adapter = new SqlDataAdapter(SqlString, Connection);
DataSet dataset = new DataSet();
adapter.Fill(dataset);
Close();
return dataset;

}
public DataRow GetDAtaRow(String SqlString)
{
DataSet dataset = GetDataSet(SqlString);
dataset.CaseSensitive = false;
if(dataset.Tables[0].Rows.Count>0)
{
return dataset.Tables[0].Rows[0];
}
else
{
return null;
}
}

}
}
...全文
23 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
idotry 2008-06-28
  • 打赏
  • 举报
回复
设置断点,逐步调试!
yagebu1983 2008-06-28
  • 打赏
  • 举报
回复
单步调试一下程序!!

110,534

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧