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

  • SEARCH
  • Home
  • 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 7597717
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T22:13:31+00:00 2026-05-30T22:13:31+00:00

I have this program that is feeding me data. I take this data (string)

  • 0

I have this program that is feeding me data. I take this data (string) and parse it so that the different fields can go into the respective db table column. I can parse the string but I can’t find the right function or way to send them to the db. This is my second time working with sql server or database in general. I have done inserts this way

MyCommand.CommandType = System.Data.CommandType.Text;
MyCommand.CommandText = "INSERT INTO TimeStampTable(ID, TimeStamp) VALUES ('24', 'sep 13, 2009')";

From what I know, CommandType only allows either text or a stored procedure. In this case, I would want to insert the string that is being parsed.

string teststring = dtString;
string[] result = teststring.Split(',', ' ', ':', '=');
Console.WriteLine("The parsed string looks like this:");
foreach (string word in result)
{
    Console.WriteLine(word);
}

This is my code that parses my incoming string. So I receive name address zip state, etc. I would like for name to go to col1, address to go to col2, etc. I think the ideal way to do this would be to convert my loop to something like this

foreach (string word in result)
{
    SqlDatasource.InsertCommand=Insert into Tablename col1 col2 col3(word);
}

Does anyone have any suggestions?

  • 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-30T22:13:33+00:00Added an answer on May 30, 2026 at 10:13 pm

    I will answer your question directly, but there are many different ways that you could go about performing the same thing (I will list some at the end)

    String insertQuery = "INSERT INTO TABLENAME (Col1, Col2, Col3...) VALUES (";
    //This is also assuming that your data is in the same order as the columns
    int isFirstLoop = true
    foreach(string word in result)
    {
        if(!isFirstLoop)
            insertQuery += ","
        insertQuery += word;
        isFirstLoop = false;        
    }
    insertQuery += ")";
    SqlDataSource.InsertCommand = insertQuery;
    

    NOTE: this is very open to SQL Injection, so keep that in mind (do you trust your incoming source). There are ways to clean the data, but ultimately, I suggest some of the methods listed below

    Alternatives:

    • Use a stored procedure over direct TSQL. Then you can map your data to SQLParameters, which (I believe) are built to scrub the data to protect against SQL Injection
    • Use a very basic ORM and/or LINQ so that you can work with objects directly. Then you only need to read the data into a POCO
    • I am sure there are other ways, however for some reason I am drawing a blank. I think that is because these are the most used alternatives 🙂
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this program that should execute a piece of code base on the
So I have this program that I really like, and it doesn't support Applescript.
I have a C/ncurses program that I'm debugging/maintaining. This program does ripoffline twice: first,
I have a program that looks something like this: public partial class It {
I have a program that simulates mouse click. Code is something like this: [DllImport(user32.dll,
I have a program that generates a .shp file, and exports this as a
I have written a program that uses qhttp to get a webpage. This works
I have an executable that is started by a windows service, this program will
This is my problem. I have a program that has to run in a
Well, I have this bit of code that is slowing down the program hugely

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.