本文整理汇总了C#中System.Data.OleDb.OleDbException类的典型用法代码示例。如果您正苦于以下问题:C# OleDbException类的具体用法?C# OleDbException怎么用?C# OleDbException使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
OleDbException类属于System.Data.OleDb命名空间,在下文中一共展示了OleDbException类的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ShowOleDbException
public void ShowOleDbException()
{
string mySelectQuery = "SELECT column1 FROM table1";
OleDbConnection myConnection =
new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;DataSource=");
OleDbCommand myCommand = new OleDbCommand(mySelectQuery,myConnection);
try
{
myCommand.Connection.Open();
}
catch (OleDbException e)
{
string errorMessages = "";
for (int i=0; i < e.Errors.Count; i++)
{
errorMessages += "Index #" + i + "\n" +
"Message: " + e.Errors[i].Message + "\n" +
"NativeError: " + e.Errors[i].NativeError + "\n" +
"Source: " + e.Errors[i].Source + "\n" +
"SQLState: " + e.Errors[i].SQLState + "\n";
}
System.Diagnostics.EventLog log = new System.Diagnostics.EventLog();
log.Source = "My Application";
log.WriteEntry(errorMessages);
Console.WriteLine("An exception occurred. Please contact your system administrator.");
}
}