Regarding class file

Posted by Bhasker under ASP.NET on 8/23/2010 | Points: 10 | Views : 938 | Status : [Member] | Replies : 5
i am beginner in asp.net. i want to create class file for insert ,delete ,update method and connection with database and use this method in asp.cx file.




Responses

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

Up
0
Down
Hi,

Class file is used where you can define the classes for entities & in that you mention the entity properties, methods. Also you can define the connection string classes to reduce lines of code.

Thanks & Regards,

Shailesh

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
can u give one example regarding this...........?

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,

class employee
{
private int _emp_id;
private string _emp_name;


public string emp_id
{ get{ return _emp_id;}
set { _emp_id = value;}
}

public void insertemp(employee objemployee)
{
//code for the adding.
}
}

Thanks & Regards,

Shailesh

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

Posted by: amit28singh-20172 on: 1/9/2013 [Member] Starter | Points: 25

Up
0
Down
But i want to write connection string in class file itself. something like this:

public static string connstr = new string("Data Source=myServerAddress;Initial Catalog=myDataBase;User Id=myUsername ;Password=myPassword ;")

And also is it possible to pass the myUsername and myPassword as parameters in above higlighted connection string.?????

Regards,
Amit Kumar Singh
DotNet Consultant

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

Posted by: Ankitsrist on: 1/9/2013 [Member] Starter | Points: 25

Up
0
Down
hey u can make class for connection string so that it will reduce ur lines of code....here is the way to write..

using System;

using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;

/// <summary>
/// Summary description for Class1
/// </summary>
public class dbClass
{
public SqlConnection sqlcon = new SqlConnection();
public void myconnection()

{
sqlcon.Close();
sqlcon.ConnectionString = ConfigurationManager.ConnectionStrings["testConnectionString"].ToString();
sqlcon.Open();
}


}


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

Login to post response