Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6880205
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T04:56:41+00:00 2026-05-27T04:56:41+00:00

I am looking for a solution to insert some data in a a table

  • 0

I am looking for a solution to insert some data in a a table using 3 parameters, the first one is the table name, and the second is a List with a class that has the name and value property.
I have a partially solution (below) for this, but i don’t think it is recommended, so, I looking for a best practice to do it.

If is possible, I’d like a suggestion to create this using parameters in order to avoid injections.

private void InsertMetada(string deviceType, List<DeviceFields> deviceFields)
 {
 DataBaseConnection database = new DataBaseConnection ();
 database.Open();
 StringBuilder strb = new StringBuilder();
 stb.Append(string.Format("INSERT INTO DEVICE_{0} ( ", deviceType.ToString().ToUpper()));
 foreach (var item in deviceFields)
 {
    strb.Append(string.Format(" {0}, ",item.name.ToString()));            
 }
 stb.Append(") VALUES ( ");
 foreach (var item in deviceFields)
 {
    strb.Append(string.Format(" '{0}', ", item.value.ToString()));
 }
 strb.Append(")");
 database.executeQuery(strb.ToString());
 database.Close();
 }

EDITED: I don’t think I was very clear in my question.
In this case, the DeviceFields.item.name has the same name of the table field.

What I am looking for is guarantee create different Device properties, for different Device Types in different tables.

Maybe my point of view is not the right one, but I thought if I have separated tables I could perform a fast search.
In this example my Table (DEVICE_KEYBOARD) looks like this:

> FIELD NAME  | TYPE
 -------------|---------
 language     | varchar   
 key          | varchar   
 isMultimedia | varchar
 deviceID     | varchar

and the list looks like

> DeviceFields[0]:
 name = language  
 value = en-us 

> DeviceField[1]:  
 name = key  
 value = 102

> DeviceField[2]:  
 name = isMultimedia  
 value = Yes

> DeviceField[3]:  
 name = deviceID  
 value = 0000-0000-00000-00000

And the second Table, for example is like:

 TABLE DEVICE_SPEAKER

> FIELD NAME   | TYPE
 --------------|---------
 rms           | varchar   
 remoteControl | varchar   
 subwoofer     | varchar
 deviceID       | varchar

It has all device fields in the first table, but this properties are specific for each kind of device…
The idea is to have opportunity to create a new property crating a new column, when the ADD button is clicked by the user, in this table, with the prefix “DEVICE_{DEVICE TYPE}”

I can list all fields when I prepare the List, my question is to know if is there a best option to create this stuff, and what could be safe and fast.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T04:56:42+00:00Added an answer on May 27, 2026 at 4:56 am

    I agree with creating a stored procedure. If you need your INSERT statements to be dynamic, this can be done within the sproc.

    http://www.codeproject.com/KB/database/Building_Dynamic_SQL.aspx

    Personally, I hate dynamic SQL in stored procedures and some would say it is bad practice, but sometimes it is the best option depending on your circumstances. I’m just throwing it out there as an option.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm looking for solution to extract some node from large xml file (using xmlstarlet
I'm looking to transfer some data from a multi-million row table into another table.
I'm using NHibernate and looking for a solution that will allow me to audit
I'm looking for a solution to convert a set of files using the terminal
I'm looking for a solution like the one discussed here, but for C# WinForms.
I'm looking for a data storage solution for a project with these requirements: The
Surprisingly can't find a match for my question. I have one table that I
I’m looking for a solution to import all the IMDB data into my own
Quick one; I know a solution, but I'm looking for something more elegant if
I'm not the first to have these issues, and will list some reference posts

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.