How to create a class library and write functions within it

Posted by Ganesh under C# on 12/2/2008 | Views : 4926 | Status : [Member] | Replies : 2
Hi,

Anybodys can give me some ideas regarding with class library file.

For example, I want to bind data in gridview from sql server table named "emp", field named "eno","ename","age" using class library




Responses

Posted by: Poster on: 12/2/2008 [Member] Starter

Up
0
Down
See the following article

http://www.vbdotnetheaven.com/UploadFile/mahesh/BuildingClassLibrary04262005091233AM/BuildingClassLibrary.aspx?ArticleID=73c74933-cc1b-49db-b90a-d459f64a0781

http://www.homeandlearn.co.uk/csharp/csharp_s16p1.html

Thanks

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

Posted by: Santoshk on: 6/16/2009 [Member] Starter

Up
0
Down
table structure:

CREATE TABLE [dbo].[Employee](

[Id] [uniqueidentifier] NULL,

[FirstName] [nvarchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,

[MiddleName] [nvarchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,

[LastName] [nvarchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,

[Designation] [nvarchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,

[Address] [nvarchar](500) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,

[Salary] [decimal](18, 2) NULL,

[DateOfJoining] [datetime] NULL

) ON [PRIMARY]





using System;

using System.Collections.Generic;

using System.Text;

using System.Data;

using System.Data.SqlClient;




namespace EmployeeDetails

{

public class Employee

{

private string _connectionString = string.Empty;

public string ConnectionString

{

get

{

return _connectionString;

}

set

{

_connectionString = value;

}

}




private string _tableName = string.Empty;

public string TableName

{

get

{

return _tableName;

}

set

{

_tableName = value;

}

}




public Employee(string server, string database, string tablename)

{

this.ConnectionString = "server=" + server + ";database=" + database + ";Integrated Security=true;pooling=false;";

this.TableName = tablename;

}




public string GetEmployeeDetails()

{

string connectionString = this.ConnectionString;

string strQry = @"SELECT * FROM " + this.TableName;

SqlConnection connection = new SqlConnection(connectionString);

SqlDataAdapter sqlDataAdapter = new SqlDataAdapter();

sqlDataAdapter.SelectCommand = new SqlCommand(strQry, connection);

connection.Open();




DataSet dataSet = new DataSet();

sqlDataAdapter.Fill(dataSet, this.TableName);

connection.Close();

return dataSet.GetXml();

}




public string GetEmployeeSchema()

{

string connectionString = this.ConnectionString;

string strQry = @"SELECT * FROM " + this.TableName;

SqlConnection connection = new SqlConnection(connectionString);

SqlDataAdapter sqlDataAdapter = new SqlDataAdapter();

sqlDataAdapter.SelectCommand = new SqlCommand(strQry, connection);

connection.Open();




DataSet dataSet = new DataSet();

sqlDataAdapter.Fill(dataSet, this.TableName);

connection.Close();

return dataSet.GetXmlSchema();

}

}

}



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

Login to post response