0

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?
}
3
Contributors
2
Replies
3
Views
6 Years
Discussion Span
Last Post by aspproject
This question has already been answered. 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.