简体   繁体   中英

WPF C# Control with variable number of columns to add value to SQL

I need a control with many columns and one row. Content of each column would be added to database. Number of columns can be varied. And depending on that I would insert data to sql table. Which is the best?

How can I insert all data from this control to sql? Maybe cycle? I do not wanna insert every column manually. But I need access to every column of it.

Sorry, I do not add tag C# and WPF

You have several options: Key-Value Table, Typed XML, Untyped XML

Key-Value: Main problem - all data types stored as string and CAST is your problem (on C# side)

CREATE TABLE VarTable (
    ColName varchar(50) NOT NULL PRIMARY KEY
    ,Value nvarchar(MAX)
)

INSERT INTO VarTable (ColName, Value)
VALUES ('CutomerID','215')
     ,('CustomerName','John')

XML

CREATE TABLE XMLTable (
    Value XML
)

INSERT INTO XMLTable (Value)
VALUES ('<MyTable><CutomerID>215</CutomerID><CustomerName>John</CustomerName></MyTable>')

SELECT TOP (1) Value FROM XMLTable

MSDN Compare Typed XML to Untyped XML

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM