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