954,574 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

ExecuteNonQuery error message

Hello.

I am 2 days old in asp.NET. I had the option to do one of my home assignments in asp.NET and I thought it would be fun. It's not been as scary as I thought. Still, I have troubles debugging my queries. I can catch errors with try-catch block, obviously, but I don't know how to get a detailed error message.
If I don't use the try-catch block, an error in the query halts the website and displays a 1-line error message in Visual Studio (if I have it open)

Since I'm using OleDb, I suspect I have to work with OleDbException or OleDbError, but I can't get it syntactically correct.

Code below works fine, without errors. Problems arise with other queries, which I'm sure are correct.

string v1 = Request["v1"];                                    
string v2 = Request["v2"];
sql2 = "INSERT INTO table(one, two) VALUES('" + v1 + "', '" + v2  + "')";

System.Data.OleDb.OleDbConnection con2 = new System.Data.OleDb.OleDbConnection();
con2.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:/Users/BB/Desktop/Database.mdb";
con2.Open();
OleDbCommand command = new OleDbCommand(sql2, con2);
command.ExecuteNonQuery();

try
{
	command.ExecuteNonQuery();
}
catch
{
	Response.Write("Error!");
	// detailed error message here?
}
Obsidian_496
Newbie Poster
23 posts since Apr 2010
Reputation Points: 10
Solved Threads: 0
 
asasasasasa
Newbie Poster
11 posts since May 2011
Reputation Points: 11
Solved Threads: 1
 

you are two times using command.ExecuteNonQuery() in your code...please correct

aspproject
Junior Poster in Training
Banned
78 posts since Apr 2011
Reputation Points: 1
Solved Threads: 3
Infraction Points: 5
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You