insert and delete works fine but i have problem to make select all data in order to make update
this is a method in db.class where connection can be perform
public void ConnectDB(CommandType CT,string ProNameSQl)
{
cn = new SqlConnection("Data Source=.;Initial Catalog=Conversation;Integrated Security=True");
cmd = new SqlCommand();
cmd.Connection = cn;
cmd.CommandType = CT;
cmd.CommandText = ProNameSQl;
cn.Open();
}
public int RunProcedure(string ProcedureName, SortedList Paraval)
{
ConnectDB(CommandType.StoredProcedure, ProcedureName);
for (int x = 0; x < Paraval.Count; x++)
{
try
{
cmd.Parameters.AddWithValue(Paraval.GetKey(x).ToString(), Paraval.GetByIndex(x));
}
catch
{
;
}
}
return ExceNoneQuery();
}
public DataTable RunSQl(string Select)
{
ConnectDB(CommandType.Text, Select);
dt=new DataTable();
dt.Load(cmd.ExecuteReader());
cn.Close();
return dt;
}
{
cn = new SqlConnection("Data Source=.;Initial Catalog=Conversation;Integrated Security=True");
cmd = new SqlCommand();
cmd.Connection = cn;
cmd.CommandType = CT;
cmd.CommandText = ProNameSQl;
cn.Open();
}
public int RunProcedure(string ProcedureName, SortedList Paraval)
{
ConnectDB(CommandType.StoredProcedure, ProcedureName);
for (int x = 0; x < Paraval.Count; x++)
{
try
{
cmd.Parameters.AddWithValue(Paraval.GetKey(x).ToString(), Paraval.GetByIndex(x));
}
catch
{
;
}
}
return ExceNoneQuery();
}
public DataTable RunSQl(string Select)
{
ConnectDB(CommandType.Text, Select);
dt=new DataTable();
dt.Load(cmd.ExecuteReader());
cn.Close();
return dt;
}
and then after check i make another class to pass the type of operation "i" refers to procdure name in sql
public bool Add()
{
return LoadProperties2List("i");
}
if every thing ok it runs to the last tire where the code can perform like insert {
return LoadProperties2List("i");
}
public class UsersInfo :MainTable
{
#region Feild
private string _id;
private string _username;
private string _SecondarySchool;
private string _University;
#endregion
#region Properties
public string id
{
get
{
return _id;
}
set
{
_id = value;
}
}
public string UserName
{
get
{
return _username;
}
set
{
_username = value;
}
}
public string SecondarySchool
{
get
{
return _SecondarySchool;
}
set
{
_SecondarySchool = value;
}
}
public string University
{
get
{
return _University;
}
set
{
_University = value;
}
}
#endregion
public override bool LoadProperties2List(string TypeOfOperation)
{
SortedList Sl = new SortedList();
Sl.Add("@CommandType", TypeOfOperation);
Sl.Add("@UserName",UserName);
Sl.Add("@SecondarySchool",SecondarySchool);
Sl.Add("@University",University);
ProcedureName = "MangeUserInfo";
if (db.RunProcedure(ProcedureName, Sl) == 1)
return true;
else
return false;
}
public bool Register(string User, string SecondaryS, string Unvi)
{
this.UserName = User;
this.SecondarySchool = SecondaryS;
this.University = Unvi;
if (Add())
return true;
else
return false;
}
this code works fine how to use these layers to sellect and retrive database and show them in textboxes ??? using the same layers
alaaPosted Aug 3, 2013, 6:14 PM
public bool find(string usernameid)
{
string query = String.Format("SELECT id FROM Users WHERE UserName='{0}'", usernameid);
DataTable tbl = SeectData(query);
if (tbl.Rows.Count == 0)
return false;
else
{
this.id = tbl.Rows[0][0].ToString();
return true;
}
}
and then call it in page load
it works fine thankx all
alaaPosted Aug 2, 2013, 5:55 AM
Akhil MittalPosted Aug 1, 2013, 11:38 PM
Put Your layers in Separate Projects for maintainability and extensibility, then reference your data access layer to business logic layer and send calls from BLL to data access using objects, Objects could be instance of classes having properties related to your database table fields.