c# - Pass xml as a parameter to a stored procedure in SQL Server -


i trying pass xml parameter c# code stored procedure in sql server doesn't work.

public static void savereceipttrans(string psitecode, string xml) {         try         {             string dbkey = "sn";             string connstr = encryption.decryptstring(configurationmanager.connectionstrings[dbkey].connectionstring);             string cmdstr = "prc_pt_fac_iu";              sqlparameter[] sqlparams = new sqlparameter[1];              sqlparams[0]            = new sqlparameter("@preceiptswithfactorynamecode", sqldbtype.xml);             sqlparams[0].direction  = parameterdirection.input;             sqlparams[0].value      = xml;              int = sqlhelper.executenonquery(connstr, commandtype.storedprocedure, cmdstr, sqlparams);         }         catch (exception ex)         {             utillogging.logexception(ex, "error -> ", psitecode);         }     } 

but no operations done on tables through stored procedure if there no call made stored procedure. have tested stored procedure dummy xml string , works fine when pass parameter c# code doesn't work.

alter procedure [dbo].[prc_pt_fac_iu] (     @preceiptswithfactorynamecode xml ) begin    set nocount on     begin try           declare @maxtransid int, @maxmoveid int, @rowcount int, @nexttransid int, @nextmoveid int       declare @idoc int       declare @tempcount int, @intflag int        select           identity(int) id,           line.item.value('@site_cde', 'char(8)') site_cde,            line.item.value('@po_nbr', 'char(17)') po_nbr,            line.item.value('@po_line_nbr', 'smallint') po_line_nbr,           line.item.value('@ran', 'int') ran,           line.item.value('@factory_name_code', 'int') factory_name_code,           null item_id,           null qty,          null cur_loc_id,          null cur_loc_status,          null trans_id,          null [user_id]                 #tmpreceiptswithfactorynamecode                   @preceiptswithfactorynamecode.nodes('/polines/poline') line(item)         select            @maxtransid = coalesce(max(trans_id),0)                 partstrack_receipt_trans (nolock)                  trans_id not null        update rt        set trans_id = @maxtransid + temp.id,           factory_name_code = temp.factory_name_code       partstrack_receipt_trans_bkp rt        inner join #tmpreceiptswithfactorynamecode temp on rt.receipt_ack_nbr = temp.ran                                                        , rt.po_nbr = temp.po_nbr                                                        , rt.po_line_nbr = temp.po_line_nbr end  public static int executenonquery(string pconnectionstring, commandtype pcommandtype, string pcommandtext, sqlparameter[] psqlparameters) {         sqlconnection lsqlconnection = null;          try         {             lsqlconnection = new sqlconnection(pconnectionstring);              sqlcommand lsqlcommand = new sqlcommand();             lsqlcommand.commandtype = pcommandtype;             lsqlcommand.connection = lsqlconnection;             lsqlcommand.commandtext = pcommandtext;             lsqlcommand.commandtimeout = 180;              if (psqlparameters != null)             {                 foreach (sqlparameter lsqlparameter in psqlparameters)                     lsqlcommand.parameters.add(lsqlparameter);             }              lsqlconnection.open();              return lsqlcommand.executenonquery();         }         catch (sqlexception sqlexp)         {             throw sqlexp;         }         catch (exception exp)         {             throw exp;         }                 {             if (lsqlconnection != null && lsqlconnection.state != connectionstate.closed)                 lsqlconnection.close();         }     } 

i searched , found correct way pass xml parameter.

then doing wrong?

thanks

edited:

i found issue. suggested methods right since xml case sensitive found mis-match in xml node passing.

try pass xml value with sqlxml. should work.


Comments

Popular posts from this blog

database - VFP Grid + SQL server 2008 - grid not showing correctly -

jquery - Set jPicker field to empty value -

.htaccess - htaccess convert request to clean url and add slash at the end of the url -