Is it necessay to insert rows one by one into database?
If this is true, I must write long SQL statement to do it.
Can I inert the whole dataset into database at a once?
The only thing you need is that you are sure that the rowstate of every row
is new added.
(This is normal if you add a row) and than you can create your own
insertcommand for the dataadapter.
The most simple one by that is let the designer do it, and than copy and
paste it from the code.
(Be aware that you can than get errors because already exisiting rows)
(You can as well use the commandbuilder by the way).
I hope this helps,
Cor.
If you use .Net 1.1 then you might have to call DTS to insert large amount
of data. I am doing that by saving the DataSet into a file (Excel file) and
then call a DTS from the C# code. I am not sure if this is the best way but
i could not think of anything else to avoid to execute an SQL statements
50.000 times if my dataset contains 50.000 rows.
By the way I do not understand how the post of Cor helps in not calling the
SQL statement for each rows you want to insert....
Francois
"ad" <fly...@wfes.tcc.edu.tw> wrote in message
news:%23Z%23hnfI4...@TK2MSFTNGP12.phx.gbl...
¤ I use WebService upload a dataset to server.
Not directly no. You can export and then import using XML but that is the only method I am aware of.
Paul
~~~~
Microsoft MVP (Visual Basic)
> By the way I do not understand how the post of Cor helps in not calling
> the
> SQL statement for each rows you want to insert....
>
If you *have* a dataset
Than you can create an SQL dataadapter
Than you can use a commandbuilder. There is not a language given so
probably even this will go (so see it as pseudo however not to far from
reality and this works only when there are not more than 100 columns in the
datatable.).
\\\\
dim ds2 as new dataset
dim da as new sqlclient("Select * from TheTable, ConnectionObject)
da.fillschema(ds2)
dim cbm as new commandbuilder(da)
da.update(TheOriginalDataset, TheDataTableToInsert)
///
Actually will by the dataadapter every row independently be processed,
however it is not calling it yourself for each row that has to be inserted.
If you want to copy a datatable than I do not prefer this method.
I hope this answers your question?
Cor
"ad" <fly...@wfes.tcc.edu.tw> wrote in message news:%23Z%23hnfI4...@TK2MSFTNGP12.phx.gbl...
How can we change the rowstate of every row in my dataset to new added?
Cor Ligthert [MVP] 寫道:
>How can we change the rowstate of every row in my dataset to new added?
That depends how you make the dataset, there are a lot of possibilities.
Cor
myAdapter.SelectCommand = myCommand;
ds = new DataSet("Customers");
myAdapter.Fill(ds);
//--------------------------------------------------------------------
The rowstate of every datarow is Unchanged.
How can I change them to Added
Cor Ligthert [MVP] 寫道:
Have a look as well to the advices given by others by Francois as you do it
like this.
However the remedy for this is very simple.
You need only to set the property of the acceptchangesduringfill to false.
I hope this helps,
Cor
"Francois Malgreve" <fran...@agoda.com_NO_SPAM> 撰寫於郵件新聞:u7jkoIJ4...@TK2MSFTNGP15.phx.gbl...
¤ I am surprised that nobody has suggested Stored Procedures yet. You can create a simple loop for your newly changed rows, and pass those values to the stored procedure. Let the SP do the work for you, and no long SQL statements.
¤
¤ HTH
¤ Altaf
¤
Yeah, I think it's the looping part (for all rows) that's going to make it real slow.
There is an sample for that on MSDN (The data part than you see it)
http://msdn.microsoft.com/vbasic/downloads/2005/code/101samples/default.aspx
The same are there for C# in another section
Using SQL statements, stored procedure and SQLDataAdapter it's all the same.
For 40.000 rows you need to do 40.000 inserts. For our situation, I cannot
see much differences between all those ways.
The ADO.NET 1.1 you can use DTS for you to do the job, or through XML.
I have problem doing that in ADO.NET 1.1 but I will post that in an other
post, after the weekend ;)
But for ADO.NET 2.0, I believe that this kind may be greatly simplified. Ad,
as you asked for a few articles, check those 2 links. But with a little
research on google you will find much more articles, but those 2 links are
all you need, I believe.
http://www.c-sharpcorner.com/Code/2004/June/BulkCopy.asp
http://msdn2.microsoft.com/en-us/library/30c3y597(en-US,VS.80).aspx
Hope this helps,
Francois.
"Francois Malgreve" <fran...@agoda.com_NO_SPAM> wrote in message
news:u7jkoIJ4...@TK2MSFTNGP15.phx.gbl...