登录
首页 » C# » C# 异常处理常用示例源码

C# 异常处理常用示例源码

于 2013-02-13 发布
0 95
下载积分: 1 下载次数: 0

代码说明:

除零异常、空引用、自定义异常示例,适合刚入门的同学学习

下载说明:请别用迅雷下载,失败请重下,重下不扣分!

发表评论

0 个回复

  • CS程序员之窗控件换肤测试版
    CS程序员之窗控件换肤测试版
    2013-09-12下载
    积分:1
  • C#连接数据库(SQL Server,MySQL,Microsoft Access,DB2,Oracle)连接字符串
    C#/.NET项目开发过程中,特别是中大型的项目,跟数据库打交道那是再正常不过的事情了。数据库可以帮助我们保存和管理数据。C#/.NET的项目中,我们也可以使用不同的数据库。 那么,我们今天就来总结整理一下C#/.NET的连接各类主流数据库(SQL Server,MySQL,Microsoft Access,DB2,Oracle)的连接字符串。 一、C#/.NET连接Microsoft SQL Server 1. 使用ODBC数据库连接 // ODBC标准连接 using System.Data.Odbc; OdbcConnection conn = new OdbcConnection(); conn.ConnectionString = "Driver={SQL Server}; Server=ServerName; DataBase=DataBaseName; Uid=UserName; Pwd=password"; conn.Open();   // ODBC受信任的连接 using System.Data.Odbc; OdbcConnection conn = new OdbcConnection(); conn.ConnectionString = "Driver={SQL Server}; Server=ServerName; DataBase=DataBaseName; Uid=admin; Pwd=password";  conn.Open();   // 或者 OdbcConnection conn = new OdbcConnection(); conn.ConnectionString = "Driver={SQL Server}; Server=ServerName; DataBase=DataBaseName; Trusted_Connection=Yes;";  2.使用OLEDB // OleDb标准连接 using System.Data.OleDb; OleDbConnection conn = new OleDbConnection(); conn.ConnectionString = "Driver=SQLOLEDB; Data Source=ServerName; Initial Catalog=DataBaseName; User id=UserName; Password=Secret;";  conn.Open(); // OleDb受信任的连接 using System.Data.OleDb; OleDbConnection conn = new OleDbConnection(); conn.ConnectionString = "Driver=SQLOLEDB; Data Source=ServerName; Initial Catalog=DataBaseName; Integrated Security=SSPI;";  conn.Open(); 3.使用.Net DataProvider // .NET DataProvider标准连接 using System.Data.SqlClient; SqlConnection conn = new SqlDbConnection(); conn.ConnectionString ="Data Source=ServerName; Initial Catalog=DataBaseName; User id=UserName; Password=Secret;";  conn.Open(); Data Source=DESKTOP-AC9DHQ6;Initial Catalog=MyKTV;Persist Security Info=True;User ID=sa;Password=mdg456123   // .NET DataProvider受信任连接 using System.Data.SqlClient; SqlConnection conn = new SqlConnection(); conn.ConnectionString = "Data Source=ServerName; Initial Catalog=DataBaseName; Integrated Security=SSPI;";  conn.Open(); 二、C#/.NET连接Microsoft Access 1.使用ODBC连接 // ODBC标准连接 using System.Data.Odbc; OdbcConnection conn = new OdbcConnection(); conn.ConnectionString = "Driver={Microsoft Access Driver (*.mdb)}; Dbq=c:myPathmyDb.mdb; Uid=Admin; Pwd=;password";  conn.Open();   // ODBC工作组(Workgroup)连接 using System.Data.Odbc; OdbcConnection conn = new OdbcConnection(); conn.ConnectionString = "Driver={Microsoft Access Driver (*.mdb)}; Dbq=c:myPathmyDb.mdb; SystemDb=c:myPathmyDb.mdw;";  conn.Open(); 2.使用OLEDB连接 // 使用OleDb的Jet标准安全连接 using System.Data.OleDb; OleDbConnection conn = new OleDbConnection(); conn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=c:mypathmyDb.mdb; User id=admin;Password=password"; conn.Open(); // 使用OleDb的Jet System Database连接 using System.Data.OleDb; OleDbConnection conn = new OleDbConnection(); conn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=c:mypathmyDb.mdb; System Database=c:mypathmyDb.mdw"; conn.Open(); 三、C#/.NET连接MySQL数据库 1.使用ODBC数据源连接 // ODBC使用MyODBC Driver的远程数据库连接 using System.Data.Odbc;  OdbcConnection conn = new OdbcConnection();  conn.ConnectionString = "Driver={MySql}; Server=192.168.0.10; Option=131072; Port=3306; Stmt=; DataBase=DataBaseName; Uid=UserName; Pwd=password;" ; conn.Open(); 2.使用OLEDB连接 // OleDb标准连接 using System.Data.OleDb; OleDbConnection conn = new OleDbConnection();  conn.ConnectionString = "Provider=MySqlProv; Data Source=ServerName; User id=UserName; Password=Password"; conn.Open(); 四、C#/.NET连接DB2数据库 1.使用ODBC连接 // 不带DSN的ODBC连接 using System.Data.Odbc; OdbcConnection conn = new OdbcConnection(); conn.ConnectionString = "Driver={IBM DB2 ODBC DRIVER};DataBase=DataBaseName; HostName=ServerName; Protocol=TCPIP;Port=PortNumber;Uid=UserName;Pwd=Secret";  conn.Open(); 2.使用OLEDB连接 // OleDb微软官方驱动 using System.Data.OleDb; OleDbConnection conn = new OleDbConnection(); conn.ConnectionString = "Driver=DB2OLEDB; Network Transport Library=TCPIP; Network Address=xxx.xxx.xxx.xxx; Package Collection=CollectionName; Initial Catalog=DataBaseName; User id=UserName; Password=Secret;";  conn.Open(); // OleDb IBM 驱动 using System.Data.OleDb; OleDbConnection conn = new OleDbConnection(); conn.ConnectionString = "Driver=IBMDADB2; DataBase=DataBaseName; HostName=ServerName; Protocol=TCPIP; Port=PortNumber; Uid=UserName; Pwd=Secret;";  conn.Open(); 3.使用.Net DataProvider第三方驱动 // 来自IBM的.NET DataProvider using IBM.Data.DB2; Db2Connection conn = new Db2Connection(); conn.ConnectionString = "DataBase=DataBaseName;Uid=UserName;Pwd=Secret"; conn.Open(); 五、C#/.NET连接Oracle数据库 1.使用ODBC连接 // ODBC 微软的官方驱动 using System.Data.Odbc; OdbcConnection conn = new OdbcConnection(); conn.ConnectionString = "Driver={Microsoft ODBC for Oracle};Server=OracleServer.world;Uid=UserName;Pwd=Secret;";  conn.Open(); // ODBC Oracle的驱动 using System.Data.Odbc; OdbcConnection conn = new OdbcConnection(); conn.ConnectionString = "Driver={Oracle ODBC Driver};Dbq=myDataBase;Uid=UserName;Pwd=Secret;";  conn.Open(); 2.使用OLEDB连接 // OleDb:Oracle驱动的标准连接 using System.Data.OleDb; OleDbConnection conn = new OleDbConnection(); conn.ConnectionString = "Driver=OraOLEDB.Oracle;Data Source=ServerName;User id=UserName;Password=Secret;"; conn.Open(); // OleD:Oracle驱动的受信任连接 using System.Data.OleDb; OleDbConnection conn = new OleDbConnection(); conn.ConnectionString = "Driver=OraOLEDB.Oracle;Data Source=ServerName;OSAuthent=1;"; conn.Open(); // 或者写成  using System.Data.OleDb; OleDbConnection conn = new OleDbConnection(); conn.ConnectionString = "Driver=OraOLEDB.Oracle;Data Source=ServerName;User id=admin;Password=pwd";  conn.Open();  
    2021-08-07 00:31:00下载
    积分:1
  • 北斗四星定位解算程序
    基于伪距的北斗导航的四星定位解算,并将解算结果转换为经纬度
    2019-08-05下载
    积分:1
  • C# 采集器 源码下载
    采集器
    2016-07-27下载
    积分:1
  • 微信回复消息 例子类源码下载
    微信帮助
    2015-01-14下载
    积分:1
  • Zend/Cache.php相关的示例代码
    Zend/Cache.php相关的示例代码,新手入门,较为常用
    2012-12-18下载
    积分:1
  • stm32单片机循迹程序(源码+原理图+GPIO分配文档)
    【实例简介】stm32f103c8t6循迹小车程序,是一个不错的寻迹避障资料
    2021-05-20 14:39:25下载
    积分:1
  • C# 设计模式观察者模式 入门级示例
    C# 设计模式观察者模式 入门级示例
    2018-11-19下载
    积分:1
  • log4net.dll 日志 使用示例 以及源码下载
    一款相当强大的开源的日志工具
    2013-08-21下载
    积分:1
  • C++ 三维折线图(提高篇-实例516).zip
    C++ 三维折线图(提高篇-实例516).zip
    2019-10-02下载
    积分:1
  • 696518资源总数
  • 104269会员总数
  • 31今日下载