Snake. net

Source: Internet
Author: User

XML Web ServiceData Exchange

 

The client calls the serverWebServices that contain dataDataset (DS):

 

Private sub synchronize ()

Dim username as string = "Johns"

Dim blnsuccess as Boolean

'UseXML Web ServiceSynchronize

Cursor. Current = cursors. waitcursor

Dim wsfeedback as new wsfeedback. Feedback

Blnsuccess = wsfeedback. insertfeedback (DS, username)

 

Cursor. Current = cursors. Default

End sub

 

Server Side Web Service acceptance Dataset And set XML Directly transfer SQL Server 2000 In the stored procedure SQLXML (English) and Openxml Analysis XML Insert new data into the appropriate table.

 

<Webmethod ()> _

Public Function insertfeedback (byval ds as dataset, byval username

String) as Boolean

Dim con as new sqlconnection (connectionstring)

Dim cmd as new sqlcommand ("p_feedback_ I", con)

Cmd. commandtype = commandtype. storedprocedure

 

'Set parameters

Dim prmxml as sqlparameter = cmd. Parameters. Add ("@ XML ",

Sqldbtype. ntext)

Prmxml. Direction = parameterdirection. Input

Prmxml. value = Ds. getxml

 

Dim prmusername as sqlparameter = cmd. Parameters. Add ("@ username ",

Sqldbtype. nvarchar)

Prmusername. Direction = parameterdirection. Input

Prmusername. value = Username

 

Try

Con. open ()

Cmd. executenonquery ()

Catch ex as exception

'Handle, record, and re-throw errors

Throw ex

 

Finally

Con. Close ()

End try

 

Return true

 

End Function

 

The stored procedure inserts the new data:

 

Create procedure p_feedback_ I

@ XML ntext,

@ Username nvarchar (50)

 

As

 

Set nocount on

 

Declare @ IDOC Integer

Declare @ ErrorInteger

 

/* Create XML document .*/

Exec sp_xml_preparedocument @ IDOC output, @ XML

 

/* Insert new records */

InsertFeedback

(

Feedbackid,

Plantsection,

Part,

Defectscope,

Scopeid,

 Defecttype,

Richink,

Username

)

SelectID,

Plantsection,

Part,

Defectscope,

Scopeid,

Defecttype,

Richink,

@ Username

From openxml (@ IDOC, '/dataset/feedback', 2)

(

IDUniqueidentifier,

PlantsectionInt,

PartInt,

DefectscopeInt,

ScopeidNvarchar (50 ),

DefecttypeInt,

RichinkNvarchar (50)

)

 

Select @ error = @ Error

If (@ error <> 0)

Begin

Goto errorhandler

End

 

/* Remove the XML document */

Exec sp_xml_removedocument @ IDOC

 

Return

 

Errorhandler:

 

If not @ IDOC is null

Exec sp_xml_removedocument @ IDOC

 

Raiserror (@ error, 16, 1)

 

Return

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.