Click here to Skip to main content
15,894,630 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
how to store data in table in database using datatable in asp.net
Posted
Comments
Tejas Vaishnav 24-Jan-14 6:08am    
what have your try so far, please share your code...

Easiest way is to use SqlBulkCopy:
C#
using (SqlConnection con = new SqlConnection(strConnect))
    {
    con.Open();
    using (SqlBulkCopy bulk = new SqlBulkCopy(con))
        {
        bulk.DestinationTableName = "Test";
        DataTable dt = new DataTable();
        dt.Columns.Add("Id");
        dt.Columns.Add("Data");
        dt.Rows.Add("ID 1", "DATA 1");
        dt.Rows.Add("ID 2", "DATA 2");
        dt.Rows.Add("ID 3", "DATA 3");
        dt.Rows.Add("ID 4", "DATA 4");
        bulk.WriteToServer(dt);
        }
    }
 
Share this answer
 
Comments
bhushan sinkar 24-Jan-14 6:25am    
using (SqlBulkCopy bulk = new SqlBulkCopy())
{
bulk.DestinationTableName = "QAtbl";
DataTable dt = new DataTable();
string Query = "Select FID , Fname, Subject FROM [Learn].[dbo].[Fdetail] Where Subject IN('DBMS')";
}

in above code i want to store these selected value to Destination table QAtbl

thnks in advance
OriginalGriff 24-Jan-14 6:33am    
So modify the query! It's pretty obvious what teh example does, isn't it?
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900