Subject: sqldataadapter
Posted By: vgsgowrisankar Post Date: 4/23/2008 4:38:34 AM
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


Reply By: robzyc Reply Date: 4/23/2008 4:57:43 AM
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
Reply By: samjudson Reply Date: 4/23/2008 7:42:49 AM
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 -/
Reply By: vgsgowrisankar Reply Date: 4/23/2008 10:05:44 AM
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
Reply By: robzyc Reply Date: 4/23/2008 10:15:18 AM
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
Reply By: samjudson Reply Date: 4/23/2008 10:18:51 AM
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 -/
Reply By: vgsgowrisankar Reply Date: 4/23/2008 12:46:28 PM
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
Reply By: samjudson Reply Date: 4/23/2008 4:32:53 PM
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 -/

Go to topic 70820

Return to index page 1