Click here to Skip to main content
15,923,006 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
hello friends

i created array list and then i stored arraylist into dataset. Then i need to store that dataset into database using sqlbulkcopy. it shows best overload method and invalid argument.

my code is
ArrayList arrayc = new ArrayList();
            arrayc.Insert(0, "hi");
            arrayc.Insert(1, "asd");
            arrayc.Insert(2, "weras");
            DataSet ds = new DataSet();
            DataTable dt = new DataTable();
            ds.Tables.Add(dt);
            ds.Tables[0].Columns.Add("name", System.Type.GetType("System.String"));
            foreach (string str in arrayc)
            {
                DataRow row = ds.Tables[0].NewRow();
                row[0] = str;
                ds.Tables[0].Rows.Add(row);
            }
            SqlConnection con = new SqlConnection("Data Source=sourceconn;database=dbname;Trusted_Connection=true");
            con.Open();
            SqlBulkCopy bc = new SqlBulkCopy(con);
            bc.BatchSize = 30;
            bc.NotifyAfter = 30;
            bc.SqlRowsCopied += new SqlRowsCopiedEventHandler(bc_SqlRowsCopied);
            bc.DestinationTableName = "ase";
            bc.WriteToServer(ds);

please tel me the solution
Posted
Updated 12-Apr-11 21:07pm
v2

Hi, refer to this article for the correct implementation of Bulk Copy with C#.Net[^]
 
Share this answer
 
Comments
beginner in C#.net 13-Apr-11 2:33am    
in that article it show only how to copy data from one database table to another.. i want to get array dataset value and store into database
By using the following Code you can insert or update from dataset to database,
C#
try
{
    SqlDataAdapter1.Update(Dataset1.Tables["Table1"]);
}
catch (Exception e)
{
    // Error during Update, add code to locate error, reconcile
    // and try to update again.
}
 
Share this answer
 
v2
Comments
beginner in C#.net 13-Apr-11 2:27am    
i couldn't get it... please explain with code

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