用于SqlServer数据库的SqlServerHelper.cs类,及其调用例子
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
namespace JonseTest
{
public class SqlServerHelper
{
public static string ConnString = string.Empty;
public static string Conn_Config_Str_Name = string.Empty;
public static string Conn_Server = string.Empty;
public static string Conn_DBName = string.Empty;
public static string Conn_Uid = string.Empty;
public static string Conn_Pwd = string.Empty;
private static string _ConnString
{
get
{
if (!string.IsNullOrEmpty(ConnString))
return ConnString;
object oConn = ConfigurationManager.ConnectionStrings[Conn_Config_Str_Name];
if (oConn != null && oConn.ToString() != "")
return oConn.ToString();
return string.Format(@"server={0};database={1};uid={2};password={3}", Conn_Server, Conn_DBName, Conn_Uid, Conn_Pwd);
}
}
// 取datatable
public static DataTable GetDataTable(out string sError, string sSQL)
{
DataTable dt = null;
sError = string.Empty;
try
{
SqlConnection conn = new SqlConnection(_ConnString);
SqlCommand comm = new SqlCommand();
comm.Connection = conn;
comm.CommandText = sSQL;
SqlDataAdapter dapter = new SqlDataAdapter(comm);
dt = new DataTable();
&nb
相关新闻>>
- 发表评论
-
- 最新评论 更多>>