C# Insert String SQL

Posted on 2004-08-15
Last Modified: 2010-05-18
I have a slight problem inserting the proper result into an MS-SQL table. The result should be <14> however all I get is PRE. BTW, the SQL command is not broken appart like you see it on this limited width posting..........

I thought using single quotes desiganted a 'string'? Help........

string pattern1 = @"(<\d{2,3}>)";

Regex r1 = new Regex(pattern1, RegexOptions.Compiled);

Match PRE = r1.Match(stringOfData);
SqlDataAdapter1.SelectCommand.CommandText = "INSERT INTO
tblMyUdpServer (col_PRE) VALUES ('PRE')";
catch(SqlException error)
Question by:kvnsdr
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions

Accepted Solution

shovavnik earned 125 total points
ID: 11804328
try this sql statement instead:

"INSERT INTO tblMyUdpServer (col_PRE) VALUES ('" + PRE + "')";

You're concatenating strings to produce a sql statement.

If that doesn't work, try this:

"INSERT INTO tblMyUdpServer (col_PRE) VALUES ('" + PRE.ToString() + "')";


Expert Comment

ID: 11807188
just an fyi, please try to use the parameter object to pass values into an insert statement.  A parameter will take care of special characters for you.  Otherwise you are setting yourself up for a possible SQL injection attack.

see the bottom of this article for some info on using parameters:;en-us;301075

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Using Third Party DLL with Access VBA 14 62
storing csv file in table variable in Python 2 93
Excel Web Add-in Where is Visual Basic used 9 72
Data Analysis 7 58
In this post we will learn different types of Android Layout and some basics of an Android App.
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

737 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question