c# - How to use XML document in SQL Server with unknown node elements? -


i have insert excel data database. structure of excel data is

service    general    sbi    bob    luxury      300       300    250    apartment   200       200    150    villa       500       400    300    

it has sent database in format

service     category    rate  luxury      general     300  luxury        sbi       300 luxury        bob       250 apartment   general     200 apartment     sbi       200 apartment     bob       150 villa       general     500 villa         sbi       400 villa         bob       300 

problem: 1: number of column unknown (max 200) in excel sheet.

i have converted excel sheet xml document , have passed parameter sql server. how use unknown column biggest problem.

if has done before, give brief description how it. xml xmldocument, passing billingconfig procedure.

sqlcommand cmd = new sqlcommand("billingconfig", con); cmd.commandtype = commandtype.storedprocedure; cmd.parameters.add("@info", sqldbtype.varchar).value = xml.innerxml; 

help appreciated

this can done using cursor in sqlserver.

  1. get column names using

    select distinct cast(attribute.name.query('local-name(.)') varchar(100)) columnname  @xml.nodes('//@*') attribute(name) 
  2. validate columns

  3. apply cursor on these convert columns rows

    declare @id varchar(10) declare @loc varchar(25) set @loc = '/mainitem/subitem';  declare @query varchar(max)          declare mycursor cursor local fast_forward     select * @tempcolumnname  open mycursor fetch next mycursor @id  while @@fetch_status = 0  begin    set @query = 'select * openxml(@hdoc, '+@loc+', 3) (xyz int)'    exec (@query)     fetch next mycursor @id end 

Comments

Popular posts from this blog

php - Why I am getting the Error "Commands out of sync; you can't run this command now" -

linux - Does gcc have any options to add version info in ELF binary file? -

java - Are there any classes that implement javax.persistence.Parameter<T>? -