PDA

View Full Version : مبتدی: فراخوانی ClassBase از DAL



noth50
سه شنبه 03 بهمن 1391, 20:11 عصر
بادرود
من در classbase

namespace DataAccessLayer
{
public class ClassBase
{
public static void ENonQuery(string ConnectionString, string comtext, CommandType commandType, params SqlParameter[] parameter)
{

SqlConnection ConObj = new SqlConnection(ConnectionString);
SqlCommand ComObj = new SqlCommand();
ComObj.CommandText = comtext;
ComObj.Connection = ConObj;
ComObj.CommandType = commandType;
ComObj.Parameters.AddRange(parameter);
ConObj.Open();
ComObj.ExecuteNonQuery();
ConObj.Close();

}
public static string EScaler(string ConnectionString,string comtext, CommandType commandType, params SqlParameter[] parameter)
{

SqlConnection ConObj = new SqlConnection(ConnectionString);
SqlCommand ComObj = new SqlCommand();
ComObj.CommandText = comtext;
ComObj.Connection = ConObj;
ComObj.CommandType = commandType;
ComObj.Parameters.AddRange(parameter);
ConObj.Open();
string retval = ComObj.ExecuteScalar().ToString();
ConObj.Close();
return retval;
}
public static SqlDataReader EReader(string ConnectionString,string comtext, CommandType commandType, params SqlParameter[] parameter)
{

SqlConnection ConObj = new SqlConnection(ConnectionString);
SqlCommand ComObj = new SqlCommand();
ComObj.CommandText = comtext;
ComObj.Connection = ConObj;
ComObj.CommandType = commandType;
ComObj.Parameters.AddRange(parameter);
ConObj.Open();
SqlDataReader dr = ComObj.ExecuteReader(CommandBehavior.CloseConnecti on);
return dr;

}
}

نوشتم
حال میخواهم این کلاس ClassBase را در UI خودم که در localhost است فراخونی کنم
باتشکر

plus
سه شنبه 03 بهمن 1391, 20:15 عصر
DataAccessLayer.ClassBase.ENonQuery( .... );

یا اینکه میتونید در بالای فایل namespace رو اضافه کنید:

using DataAccessLayer;

و بعد:

ClassBase.ENonQuery( .... );

noth50
سه شنبه 03 بهمن 1391, 20:20 عصر
من این دو کار را انجام دادم

DataAccessLayer.ClassBase.ENonQuery( .... );


using DataAccessLayer;

ولی جواب نمیده کلا DataAccessLayer دو نمیشناسه

plus
سه شنبه 03 بهمن 1391, 20:27 عصر
فایلی که DataAccessLayer نوشته شده و فایلی که ازون میخواد استفاده کنه باید توی 1 پروژه باشن.در غیر این صورت، باید پروژه ای که DataAccessLayer توش تعریف شده Class Library ساخته بشه و توی پروژه ای که قراره ازش استفاده بشه، Add Reference بشه.