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

Home Posts Topics Members FAQ

Webmethod to save data to SQLServer

Rob
I have a Webservice written in C# that provides data to both a web browser
through ASP.net and to a VC++ client. I have been able to retrieve data
from SQLServer and passing to my C++ client as XML without a problem using
the SqlDataAdaptor and the DataSet. I am a bit confused how to save data to
SQL Server from my client.

I figured if I could create a DataSet, I could save it to the database. I
wrote a WebMethod that takes a string (the XML) as input, reads that string
using an XMLReader, then creates a DataSet from that reader.

[WebMethod]
public Boolean SaveStaff(strin g sStaffXML)
{
XmlReaderSettin gs settings = new XmlReaderSettin gs();
settings.Confor manceLevel = ConformanceLeve l.Fragment;
settings.Ignore Whitespace = true;
settings.Ignore Comments = true;
XmlReader reader = XmlReader.Creat e(sStaffXML, settings);

// Create a new DataSet.
DataSet staffDataSet = new DataSet("Staff DataSet");

// Read the XML document into the DataSet.
staffDataSet.Re adXml(reader);

// Close the XmlTextReader
reader.Close();

SqlDataAdapter dataAdapter;

SqlConnection conn;
conn = new SqlConnection(" Server
=localhost;uid= stmUser;pwd=myp w;database=STMD B");

string cmdString = "SELECT * FROM Staff"; // NOT SURE IF I NEED
THIS!

dataAdapter = new SqlDataAdapter( cmdString, conn);

dataAdapter.Upd ate(staffDataSe t);

return true;
}

Is this the right approach?

I also wasn't sure exactly how to build the XML string so that I can pass it
into the DataReader and then let .NET do its magic. Do I need to use an XSD
file? Can I just emulate the XML that .NET passes to the client when it
calls a data retrieval method that returns XML with Staff records in it?

Are there any good articles about how to do this. most of the stuff out
there about using web services use examples of retrieving data, not saving
it.

Regards,

-Rob
Jan 16 '07 #1
0 1901

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
420
by: Lars Moastuen | last post by:
I'm currently writing a webservice. I've successfully written a service that gives me some XML data, but now I want to link a XLS-stylesheet to that data. The way I'm trying to do that is to create a webmethod that returns a XmlDataDocument, and use CreateProcessingInstruction() to add a "stylesheet-header"... Problem is that the headers I add using CreateProcessingInstruction() seems to be removed (?) when the data is transferred over the...
7
24460
by: Niyazi | last post by:
Hi, I developed an application and I am using SQL Server 2000 developer edition. I create my database and I have also created tbl_USER table. I have an ID, RealName, UserName, and UserPassword fields. I want to save UserName and UserPassword using bit or binary data type with VB.NET. Then ofcourse I have to retrive them to compare it later and if I find match than user can enter the MAIN forum.
3
2663
by: sd | last post by:
Hello All, I aplogize if this has already been answered however I couldn't find anything related to this... I have bunch of webservices written in vb.net returning native data types, due to constraints of the client I need to return data that has been output escaped i.e. when a string response is returned back by the service it automatically converts & to amp; and the other reserved chracters, in this case I don't want the conversion to
7
4147
by: John J. Hughes II | last post by:
I need to save a DWORD to the sql server, the below posts an error, any suggestions on what I am doing wrong. I have the column in the sql server defined as an int since unsigned int is not valid. Also trying to avoid setting it to a bigint in the server. Casting an int to an uint use to work in C++. System.Data.SqlClient.SqlConnection cn = new System.Data.SqlClient.SqlConnection(...); cn.Open()
5
10378
by: LS | last post by:
Can a WebMethod return an Interface type? Can we pass an interface parameter ? Example : public interface IEntity { long Id { get; set; } string Name { get; set; } }
2
2845
by: Peter McEvoy | last post by:
Folks, I've been building a Webservice API for a contract that will be exposed to the internet at large. There are two endpoints, and each endpoint contains a number of webmethods. Every webmethod returns a returncode which indicates the level of success in performing the operation (as well as the actual results of the call in an "out" parameter) They have a requirement that when they want to perform maintenance on the backend system,...
1
3735
by: Rameel | last post by:
Friends, I'm probably being more critical with VB.Net Windows application. I have Developed VisualStudio 20005 VB.Net Windows application how willl i be able to save a specific record into my database file throu GUI Save Record button? As i write the comand as foloow but it is not inserting the new record in to the Access Database. Public Function Open_Connection() As Boolean Try Select Case...
2
3888
by: toddw607 | last post by:
Hi all! I am attempting to bring an SQL Server table into ASP.NET using the datagrid . I have set all cells to be a text box by which the user can just click on and edit the cell. I have a save button and when I click the save button the page reloads and the new data is in the cell, however when I close out and come back in the data is no longer there. I have a databind() subroutine which includes a postback included within my code for...
3
7167
by: =?Utf-8?B?YzY3NjIyOA==?= | last post by:
Hi all, I have a question for you. I have a .csv file which has many lines of data. Each line has many data fields which are delimited by ",". Now I need to extract part of data from this file but save it as an excel file. The data in this excel file will be imported into an Access database. The
0
9705
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...
0
9576
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10323
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9138
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...
1
7613
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6847
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
5515
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
5647
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2983
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.