 |
C# 2005 For discussion of Visual C# 2005. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the C# 2005 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|

April 23rd, 2008, 04:38 AM
|
Authorized User
|
|
Join Date: Mar 2008
Posts: 23
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
sqldataadapter
hai sir,
i have designed the application in c#.net window application. i want to insert the records in sql db. which one is best way.
1. direct execution into the databse using executenonquery.
(or)
2. insert the new row into the dataset and update this
dataset to the db.
but each and every record immediatly stored into the db.
and one more process. each and every insertion record get the record id from another one table called autoval.
in this autoval table i already stored the records .
form_id nextid
proj 4565
sales 5677
each and every insertion time i get the id from this table and update the next id in the same table.
thank you sir
|

April 23rd, 2008, 04:57 AM
|
Friend of Wrox
|
|
Join Date: Mar 2007
Posts: 432
Thanks: 0
Thanked 1 Time in 1 Post
|
|
Hi there,
I would say it would be best to use SQL INSERT statements to insert new records. Creating a DataSet seems far too much for this simple case.
If you are inserting many records, I would also suggest creating a stored procedure so you can prepare an execution plan.
Rob
http://robzyc.spaces.live.com
|

April 23rd, 2008, 07:42 AM
|
 |
Friend of Wrox
|
|
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
|
|
Firstly, I would recommend using an autonumber or IDENTIY column, rather than the autoval table like you are suggesting.
Secondly, as Rob says, do the whole thing in a stored procedure.
Thirdly you should look at the SqlCommand object, together with parameters to pass in your values to execute ANY sql. You should ideally never be executing a concatenated SQL string.
/- Sam Judson : Wrox Technical Editor -/
|

April 23rd, 2008, 10:05 AM
|
Authorized User
|
|
Join Date: Mar 2008
Posts: 23
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Sir I am using adapter to load the current records from db to dataset and I dispose the adapter. So it means now I am getting the records using adapter. But if I insert the record from the application, it should be immediately reflect in database table.
So there is a two way to store the records one method is
1. Direct execute nonquery ()
2. By using adapter insert command we can store the records in dataset and then
We can update that dataset into db.
But I think, by using adapter concept we can store larger number of records and we can perform large number of process in our local dataset. Finally by using adapter we can store the dataset updates to the underlying database.
But in our case we have to do the each and every process in db immediately. So shall I use adapter to fill the dataset. And use execute non query concept for direct update into the database sir.
Thank you sir
|

April 23rd, 2008, 10:15 AM
|
Friend of Wrox
|
|
Join Date: Mar 2007
Posts: 432
Thanks: 0
Thanked 1 Time in 1 Post
|
|
Correct me if I am wrong, but you have just asked the same question?!
DataSets/DataAdapters are designed for disconnected data manipulation, but from what you are saying you want [ almost] connected (I say almost because the connection is not always active).
But you want the changes persisted to data straight away. I would therefore then say it is best to use a stored procedure and execute the required update as you wish?
Rob
http://robzyc.spaces.live.com
|

April 23rd, 2008, 10:18 AM
|
 |
Friend of Wrox
|
|
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
|
|
It depends largely on what you are going to do with the DataSet after you have updated the records. If you expect the DataSet to be kept up to date then use the DataAdapter, simply call Update() after you add each row to the DataSet.
If however you don't care about the DataSet once you have retrieved it and are concerned more for performance, then do the insert directly.
/- Sam Judson : Wrox Technical Editor -/
|

April 23rd, 2008, 12:46 PM
|
Authorized User
|
|
Join Date: Mar 2008
Posts: 23
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Thank you sir for your correct guidelines. Finally I decided to use datareader() to select the records . By using this I create the dataset for view. But I donât use sqldataadapter. Because datareader is faster than adapter is it sir?
And for other process such as insert, delete, update I use direct execution query and stored procedure. Is it right way sir?
Thank you sir
|

April 23rd, 2008, 04:32 PM
|
 |
Friend of Wrox
|
|
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
|
|
As I said, it depends what you are doing with your DataSet. I doubt very much that manually creating a DataSet using a DataReader is going to be any faster than using SqlDataAdapter.
There is no 'right' way - it depends on what your requirements are.
/- Sam Judson : Wrox Technical Editor -/
|
|
 |