用于对数据库进行操作的类库 --- 经验的总结 ( 二)C#
public static string GetData( string firstName, string lastName, ref DataSet ds)
{
SqlConnection conn= new SqlConnection(connectionString) ;
SqlDataAdapter da= new SqlDataAdapter("Pro_GetUserInfo",conn);
para0= new SqlParameter("@firstName",firstName);
para1= new SqlParameter("@lastName",lastName);
da.SelectCommand.Parameters.Add(para0);
da.SelectCommand.Parameters.Add(para1);
da.SelectCommand.CommandType=CommandType.StoredProcedure;
try
{
conn.Open();
da.Fill(ds);
conn.Close();
}
catch (Exception ex)
{
If(conn.State == ConnectionState.Open)
{
conn.Close();
}
return ex.ToString();
}
}
using System;
using System.Data;
using System.Configuration;
using System.Data.SqlClient;
using System.Data.SqlTypes;
using System.Collections;
public class CSqlHelper
{
string ConnStr = String.Empty;
public CSqlHelper()
{
//ConnStr = ConfigurationSettings.AppSettings["sqlConstr"];
ConnStr = sqlConstr;
}
public static string sqlConstr = "";
评论0
最新资源