using System.Collections.Generic;
using System.Text;
namespace map_1.baseclass
{
class Sql_DataBase
{
建立数据库连接#region 建立数据库连接
/// <summary>
/// 建立数据库连接.
/// </summary>
/// <returns>返回SqlConnection对象</returns>
public SqlConnection Get_con()
{
string sqlstr = "Data Source=;Database=;Integrated Security=SSPI";
SqlConnection myCoon = new SqlConnection(sqlstr);
return myCoon;
}
#endregion
执行SqlCommand命令#region 执行SqlCommand命令
/// <summary>
/// 执行SqlCommand
/// </summary>
/// <param name="M_str_sqlstr">SQL语句</param>
public void getcom(string M_sqlstr)
{
SqlConnection sqlcon = this.getcon();
sqlcon.Open();
SqlCommand sqlcom = new SqlCommand(M_sqlstr, sqlcon);
sqlcom.ExecuteNonQuery();
sqlcom.Dispose();
sqlcon.Close();
sqlcon.Dispose();
}
#endregion
创建DataSet对象#region 创建DataSet对象
/// <summary>
/// 创建一个DataSet对象
/// </summary>
/// <param name="M_str_sqlstr">SQL语句</param>
/// <param name="M_str_table">表名</param>
/// <returns>返回DataSet对象</returns>
public DataSet getds(string M_sqlstr, string M_table)
{
SqlConnection sqlcon = this.getcon();
SqlDataAdapter sqlda = new SqlDataAdapter(M_sqlstr, sqlcon);
DataSet myds = new DataSet();
sqlda.Fill(myds, M_table);
return myds;
}
#endregion
创建SqlDataReader对象#region 创建SqlDataReader对象
/// <summary>
/// 创建一个SqlDataReader对象
/// </summary>
/// <param name="M_str_sqlstr">SQL语句</param>
/// <returns>返回SqlDataReader对象</returns>
public SqlDataReader getread(string M_sqlstr)
{
SqlConnection sqlcon = this.getcon();
SqlCommand sqlcom = new SqlCommand(M_sqlstr, sqlcon);
sqlcon.Open();
SqlDataReader sqlread = sqlcom.ExecuteReader(CommandBehavior.CloseConnection);
return sqlread;
}
#endregion
}
}