how to use class file method in aspx.cs file

Posted by Bhasker under Regular Expressions on 8/23/2010 | Points: 10 | Views : 15173 | Status : [Member] | Replies : 5
dear all
can u explain with one small example for class file. how i ll use for connection and different method like insert,update,delete




Responses

Posted by: SurajRane on: 8/23/2010 [Member] Starter | Points: 25

Up
0
Down
Its simple.

create new aspx page.
press F7 to go to code behind ie. aspx.cs file.

Ok. Now create to create a class. right click your project -> say add New --> select class --> rename it as DbOperations

it will look like below example

public class DbOperation
{
private static SqlConnection conn= new SqlConnection("write connection string here..");

public static void Insert(param1,param2)
{
SqlCommand cmd =new SqlCommand();
cmd.CommandText="insert into table .... param1,param2.."
cmd.Connection=conn;
con.open()

cmd.ExecuteNonQuery();
con.close()
}
}


you can easily get code for creating connetcion and executing command using c#. just google a while or you can read articles here ..




Bhasker, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Bhasker on: 8/23/2010 [Member] Starter | Points: 25

Up
0
Down
THEN SIR HOW I LL USE INSERT METHOD IN ASPX.CS FILE

Bhasker, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Shankul2784 on: 8/23/2010 [Member] Bronze | Points: 25

Up
0
Down
Hi,

create a instance of the class like

DbOperation objDbOperation =new DbOperation ();

& call the method

DbOperation.insert(params);



Thanks & Regards,

Shailesh

Bhasker, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: SurajRane on: 8/24/2010 [Member] Starter | Points: 25

Up
0
Down
Shankul2784 is right !!

but code provided above contains static methods.

create static methods so that there will be no need to create instance of class you can directly call it using class name like below

-- DbOperation.Insert()

Here we are just providing you a hint for solving your problem.we cant provide you everything here.

Bhasker, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Santosh0683 on: 8/24/2010 [Member] Starter | Points: 25

Up
0
Down
hi i hope it help..
protected void GridViewBind()
{
try
{
//EmpBll class define in app_code and call here .aspx.cs code
EmpBll objEmpBll = new EmpBll()
Ds = objEmpBll.GetEmp();
if (Ds.Tables[0].Rows.Count > 0)
{
gvEmp.DataSource = Ds;
gvEmp.DataBind();
}
}
catch (Exception ex)
{
msgl.Text = ex.Message;
}
}

Santosh Singh
http://aspdotnetcode.blogspot.in/

Bhasker, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response