C# SQL INSERT String???
-
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 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()); } }
-
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 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()); } }
Ummmm... Are you trying to say that the
VALUES('PRE')
in yourCommandText
is supposed to be the result ofMatch PRE = r1.Match(stringOfData)
???
"If a man empties his purse into his head, no man can take it away from him, for an investment in knowledge pays the best interest." -- Joseph E. O'Donnell Can't manage to P/Invoke that Win32 API in .NET? Why not do interop the wiki way!
-
Ummmm... Are you trying to say that the
VALUES('PRE')
in yourCommandText
is supposed to be the result ofMatch PRE = r1.Match(stringOfData)
???
"If a man empties his purse into his head, no man can take it away from him, for an investment in knowledge pays the best interest." -- Joseph E. O'Donnell Can't manage to P/Invoke that Win32 API in .NET? Why not do interop the wiki way!
-
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 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()); } }
You are inserting hardCoded "PRE" value rather than variable PRE Change your sql to SqlDataAdapter1.SelectCommand.CommandText = "INSERT INTO tblMyUdpServer (col_PRE) VALUES (" + PRE.Value + ")"; Sanjay Sansanwal www.sansanwal.com