Click here to Skip to main content
15,897,518 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i want to write a method in dal

i am new...

plz guide me
Posted

Sure ur DAL is a Class library ,if it is then add a class in it wiht some specifc name and u can create there any methods u want.


C#
public DataTable GetEntity(string sqlQuery)
        {
            DataTable dt = new DataTable();
            dt.Rows.Clear();
            sqlAdapter = new SqlDataAdapter(sqlQuery, sqlConn);
            sqlAdapter.Fill(dt);
            sqlAdapter.Dispose();
            return dt;
        }

the thing is that build the DAl after completing coding in created class and the whole application then u can access those methods with object.mehodname anywhere
 
Share this answer
 
v2
A very good example of class library
MSDN
 
Share this answer
 
Comments
Jaydev Deva 8-Jun-22 0:38am    
simple interface
Have a look at below link.

http://www.15seconds.com/issue/030317.htm
 
Share this answer
 
you can define method as follows :

C#
public string GetName()
{
    return "Name";
}


you can call this method as follows :

C#
string a = GetName();


-Sagar Solanki
 
Share this answer
 
"procAvailableStuff" will be your stored procedure...you can google wt a stored procedure is...


C#
public DataTable grid(string date)
        {
            using (SqlConnection con = new SqlConnection(ConnString))
            {
                SqlCommand cmd = new SqlCommand("procAvailableStuff", con);
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.Add(new SqlParameter("@Date", SqlDbType.NVarChar));
                cmd.Parameters["@Date"].Value = date;
                DataTable dTable = new DataTable("EmployeeName");
                SqlDataAdapter adapter = new SqlDataAdapter(cmd);
                adapter.Fill(dTable);
                return dTable;

            }

        }
 
Share this answer
 
v2
//this function wont return a value will do the task
public void MyFirstMethod()
{
   int a=10;
   int b=10;
   int c= a+b;
}

//this function return a  string value will do the task
public string MyFirstMethod()
{
   return "napster"   ;
}

//this function return a  string value will do the task
public string MyFirstMethod()
{
   return "napster"   ;
}

//this function accepts 2  parameters string will use do the task
public void MyFirstMethod(string a, string b)
{
  string s= a + " " + b;
}


Actually it is example of function overloading too :) happy learning
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900