473,394 Members | 1,679 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

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(string sStaffXML)
{
XmlReaderSettings settings = new XmlReaderSettings();
settings.ConformanceLevel = ConformanceLevel.Fragment;
settings.IgnoreWhitespace = true;
settings.IgnoreComments = true;
XmlReader reader = XmlReader.Create(sStaffXML, settings);

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

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

// Close the XmlTextReader
reader.Close();

SqlDataAdapter dataAdapter;

SqlConnection conn;
conn = new SqlConnection("Server
=localhost;uid=stmUser;pwd=mypw;database=STMDB");

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

dataAdapter = new SqlDataAdapter(cmdString, conn);

dataAdapter.Update(staffDataSet);

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 1875

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

Similar topics

3
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...
7
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...
3
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...
7
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....
5
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
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...
1
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...
2
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...
3
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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...
0
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...

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.