0

i am having an sql query in catch block. the code is:

Dim str_exception As String = ex.Message 
 

Dim sql5 As String = "insert into table_data(type,description) values('ERROR'," + str_exception + ")"  
 

Dim cmd_sql5 As New SqlCommand(sql5, connection) 
cmd_sql5.ExecuteScalar()

it throws an exception at cmd_sql5.ExecuteScalar(). the exception is - incorrect syntax near 'records' . i tried adding single quotes like ' incorrect syntax near 'records' .' .but still it is giving me the same error. I think it is because of the quotes near records. this exception is thrown somewhere else in the code and then it comes to cath block. i want to save the exception in the database.

how can i get rid of this error?

4
Contributors
3
Replies
4
Views
6 Years
Discussion Span
Last Post by Netcode
0

Use ExecuteNonQuery() method, instead of ExecuteScalar().
ExecuteScalar() method in only used to get, set only one value.

Edited by Mitja Bonca: n/a

0

You might also want to change your query to

Dim sql5 As String = "insert into table_data(type,description) values('ERROR','" + str_exception + "')"

\
(Added single quotes to str_exception)

-1

you may want to try this:

Dim sql5 As String = "insert into table_data(type,description) values('ERROR','" + str_exception + "')"

Dim cmd_sql5 As New SqlCommand(sql5, connection)

connection.Open()
	cmd_sql5.ExecuteNonQuery()
connection.Close()
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.