473,804 Members | 3,113 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

SqlDataAdapter Problem

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("sel ect * 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
1 2107
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.Sel ectStatement.Co mmandText = "....";

Saso

"Steven Blair" <st**********@b tinternet.com> wrote in message
news:bo******** **@sparta.btint ernet.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("sel ect * 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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
3155
by: Programatix | last post by:
Hi, I'm working on a WebService project. I'm trying to validate data before they are updated to the database by handling the RowUpdating event for a SqlDataAdapter. The data being handled has DataRelation which is related to another DataTable. As for that, I also need to retrieve the DataRelation from the current row being updated. I wrote a code which look something like this, Dim relation As DataRelation
0
925
by: Steven Blair | last post by:
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:
2
2499
by: Sgt. Sausage | last post by:
New to multi-threading (less than 24 hours at it <grin>) Anyway, it's all making sense, and working fairly well thus far, but I'm having a minor issue I'm not sure how to get around. I've got a form that uses SqlDataAdapter. It fires off a thread to fill a DataSet. Not a big deal, this works. I've also got a requirement that the Thread that's going off to do the work -- if it takes too long, it has to
10
2534
by: Victor | last post by:
Hello there, I have a module in VB.NET (ASP.NET) and on top I declare the SqlConnection and the SqlDataAdapter. Like: Module AccessDB Dim sqlCmd As New SqlCommand Dim conAanvraag As New
7
3004
by: Matt Jensen | last post by:
Howdy Fairly simple question I think, I presume the answer is no it can't be reused for 2 *SELECT* statements, but just hoping for clarification. Just asking in the interests of trying to minimise code. i.e. if the SqlDataAdapter uses a connection to the one database for a select statement and I want to do a second select statement on exactly the same database, can I reuse the SqlDataAdapter? I ask because I want to put both 'select'...
4
5300
by: HS1 | last post by:
Hello. I declare a SqlDataAdapter in a FormLoad as below. However, there is error claimed that the SqlDataAdapter is not defined. Could you please tell me what to do ------------------ Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
1
1753
by: archana | last post by:
Hi all I ma having problem in sqldataadapter. In my sql database i have one table containing column name as 'Name and address'. Here 'and' is reserved word which i am using in column name. In sql server at a time of inserting data into the table it is working properly. But when i try to insert data through sqldataadapter in C#, it is
1
8076
by: languy | last post by:
Hi there I'm having a problem when using the SqlDataAdapter. When calling the Update(DataSet, string) method I get the following error message "String or binary data would be truncated". The rows neither have data that exceeds 8000 chars nor contain any LOB fields. Furthermore the data is transferred between two tables that are bitwise identical. -- snip -- System.Data.SqlClient.SqlCommand command =
3
1650
by: Spectre1337 | last post by:
Hello, I've encountered a rather puzzling problem with SqlDataAdapter. I've set up a number of elaborate tables in the Microsoft SQL Server Management Studio Express (including several table key relationships), and I've been successfully accessing all of that information through the classes generated by the "visual" DataSet file in Web Developer Express (Solution > Add New Item > Data Set). Prior to my last code modification I've...
0
9706
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
1
10321
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10077
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9152
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6853
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5522
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5651
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4300
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2991
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.