?
Solved

C# Insert String SQL

Posted on 2004-08-15
2
Medium Priority
?
1,073 Views
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);
{
try
{
connection1.Open();
SqlDataAdapter1.SelectCommand.CommandText = "INSERT INTO
tblMyUdpServer (col_PRE) VALUES ('PRE')";
SqlDataAdapter1.SelectCommand.ExecuteNonQuery();
connection1.Close();
}
catch(SqlException error)
{
MessageBox.Show(error.Message.ToString());
}
listBox1.Items.Add(PRE.ToString());
}
}
0
Comment
Question by:kvnsdr
[X]
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
2 Comments
 
LVL 8

Accepted Solution

by:
shovavnik earned 500 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() + "')";

0
 
LVL 5

Expert Comment

by:LlamaJoe
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:
http://support.microsoft.com/default.aspx?scid=kb;en-us;301075
0

Featured Post

Independent Software Vendors: 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

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.
Q&A with Course Creator, Mark Lassoff, on the importance of HTML5 in the career of a modern-day developer.
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…
Starting up a Project

650 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