Sunday, August 3, 2014

Dataset To another dataset



Dataset to another dataser

CREATETABLE [dbo].[tbl_empList](
      [ID] [int] NULL,
      [NAME] [nvarchar](50)NULL,
      [GENDER] [nvarchar](20)NULL)

<%@PageLanguage="C#"AutoEventWireup="true"CodeFile="Datatabletoanother.aspx.cs"Inherits="Datatabletoanother"%>

<!DOCTYPEhtmlPUBLIC"-//W3C//DTD XHTML 1.0 Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<htmlxmlns="http://www.w3.org/1999/xhtml">
<headrunat="server">
<title></title>
</head>
<body>
<formid="form1"runat="server">
<div>
<asp:GridViewID="GridView1"runat="server"></asp:GridView>
</div>
</form>
</body>
</html>

using System;
usingSystem.Collections.Generic;
usingSystem.Linq;
usingSystem.Web;
usingSystem.Web.UI;
usingSystem.Web.UI.WebControls;
usingSystem.Data.SqlClient;
usingSystem.Data;

publicpartialclassDatatabletoanother : System.Web.UI.Page
{
protectedvoidPage_Load(object sender, EventArgs e)
    {
using (SqlConnection con = newSqlConnection(@"Data Source=NARESH-PC\SQLEXPRESS;InitialCatalog=naresh;Integrated Security=True"))
        {
SqlCommandcmd = newSqlCommand("select * from tbl_empList", con);
DataSetdsSource = newDataSet();
DataSetdsDest = newDataSet();

SqlDataAdapter da = newSqlDataAdapter(cmd);
da.Fill(dsSource);
foreach (DataTablesourceTableindsSource.Tables)
            {
dsDest.Tables.Add(sourceTable.Copy());
            }
            GridView1.DataSource = dsDest;
GridView1.DataBind();
        }

    }
}