By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,759 Members | 959 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,759 IT Pros & Developers. It's quick & easy.

SqlDataAdapter Problem

P: n/a
Hi,

Here is a short decsription of my problem.

I have written a dll for Database accessing. I have one method which can
return a Dataset and another method which takes a Dataset and upates a
Database. (Disconnected Datasets).
The problem I have is a new SqlAdapter is required before updating the
Database:
Therefore, to allow the update I have to do the following:

m_DataAdaptor = new SqlAdapter("select * from club",m_Conn);

I want a generic method for updating, but this way means I have to put a
hardcoded SQL string as the first parameter. The connection object is a
class member and the DataSet is passed in from the client.

Basically, what I want is a method that takes a Dataset as a parameter and
can update a Database.

One idea I had was to make the SqlDataAdapter a method of the DB class. This
means the SqlDataAdapter would stay in scope during the life of the object
(DB class).

Is there some other method of updating a Database using a Dataset ?

Any help / suggestions would be appreciated

Regards,

Steven
www.stevenblair.com
Nov 15 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
the SqlDataAdapter has (among others) 4 properties:
SelectStatement, InsertStatement, UpdateStatement, DeleteStatement...

When you create the dataAdapter using the wizard you also select, which
table are you going to be working with...
Now when you call:
sqlDataAdapter.Fill(dataSet);
it calls it's SelectStatement and gives the dataSet a schema which is the
same as the selected columns in the table...

Now you edit the dataSet and you call
sqlDataAdapter.Update(dataSet);
the dataAdapter now calls it's UpdateStatement, which looks like "UPDATE
table SET col1 = 1 ... coln = N WHERE..."

I'm not sure it's possible to write a generic class...

I may be wrong...

The sql string doesn't have to be hardcoded... why not use column names as
parameters (or properties) and construct the sql query during runtime?

btw. you don't have to create a new DataAdapter each time... you can just
say:
DataAdapter.SelectStatement.CommandText = "....";

Saso

"Steven Blair" <st**********@btinternet.com> wrote in message
news:bo**********@sparta.btinternet.com...
Hi,

Here is a short decsription of my problem.

I have written a dll for Database accessing. I have one method which can
return a Dataset and another method which takes a Dataset and upates a
Database. (Disconnected Datasets).
The problem I have is a new SqlAdapter is required before updating the
Database:
Therefore, to allow the update I have to do the following:

m_DataAdaptor = new SqlAdapter("select * from club",m_Conn);

I want a generic method for updating, but this way means I have to put a
hardcoded SQL string as the first parameter. The connection object is a
class member and the DataSet is passed in from the client.

Basically, what I want is a method that takes a Dataset as a parameter and
can update a Database.

One idea I had was to make the SqlDataAdapter a method of the DB class. This means the SqlDataAdapter would stay in scope during the life of the object
(DB class).

Is there some other method of updating a Database using a Dataset ?

Any help / suggestions would be appreciated

Regards,

Steven
www.stevenblair.com

Nov 15 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.