i want return error occured @ time of update in sql server 2008.
now want display error user can understand goes wrong.
how should in c#?
thanks.........
errors when performing sql statement against database raise exception in connector. exceptions of type sqlexception and, such, have message property contains user friendly description of error.
remember though while user-friendly, message aimed @ developers. should not display end-user.
as usual, trap exception have use try-catch block:
try { sqlconnection conn = null; conn = new sqlconnection(connstring); // connstring connection string database conn.open(); var strsqlcommand = "select* table"; // statement wrong! raise exception var command = new sqlcommand(strsqlcommand, conn); var ret = command.executescalar(); conn.close(); return ret; } catch (sqlexception e) { console.writeline(e.message); }
this example of course assumes console application.
Comments
Post a Comment