您现在的位置是:首页 >

this可以出现在类方法中吗 C#中DataReader类的使用

火烧 2022-08-29 22:02:30 1035
C#中DataReader类的使用     u i g Sy tem u i g Sy tem IO u i g Sy tem Data OleD ame ace Co oleComma dDemo
this可以出现在类方法中吗 C#中DataReader类的使用

C#中DataReader类的使用  

  

  using System;        using System IO;        using System Data OleDb;        namespace ConsoleCommandDemo        {            /// <summary>            /// Class 的摘要说明             /// </summary>            class CommandClass            {                /// <summary>                /// 应用程序的主入口点                 /// </summary>                [STAThread]                static void Main(string[] args)                {                    string strCon = @ Provider=Microsoft Jet OLEDB ;Data Source=DataBase mdb; ;                    // 定义连接                    OleDbConnection MyCon = new OleDbConnection(strCon);                    try                    {                        MyCon Open();                        string strSQL = @ INSERT INTO ADODemo (姓名 年龄) VALUES ( 赵六 ) ;                        OleDbCommand MyCom = new OleDbCommand(strSQL MyCon);                        // 执行没有返回结果的指令                        Console WriteLine( 执行的命令:{ } MyCom CommandText);                        Console WriteLine( 执行结果影响了:{ }个记录 MyCom ExecuteNonQuery());                        // 删除一条记录                        strSQL = @ delete from ADODemo where (姓名 = 赵六 ) ;                        MyCom CommandText = strSQL;                        Console WriteLine( 执行的命令:{ } MyCom CommandText);                        Console WriteLine( 执行结果影响了:{ }个记录 MyCom ExecuteNonQuery());                        // 使用参数插入一条记录                        MyCom CommandText = INSERT INTO ADODemo (姓名 年龄) VALUES (? ?) ;                        MyCom Parameters Add( @姓名 OleDbType VarChar );                        MyCom Parameters Add( @年龄 OleDbType TinyInt);                        MyCom Parameters[ @姓名 ] Value = 赵六 ;                        MyCom Parameters[ @年龄 ] Value = ;                        Console WriteLine( 执行的命令:{ } MyCom CommandText);                        Console WriteLine( 执行结果影响了:{ }个记录 MyCom ExecuteNonQuery());                        // 删除一条记录                        strSQL = @ delete from ADODemo where (姓名 = 赵六 ) ;                        MyCom CommandText = strSQL;                        Console WriteLine( 执行的命令:{ } MyCom CommandText);                        Console WriteLine( 执行结果影响了:{ }个记录 MyCom ExecuteNonQuery());                        // 浏览数据                        strSQL = @ select * from ADODemo ;                        MyCom CommandText = strSQL;                        OleDbDataReader MyDataReader = MyCom ExecuteReader();                        // 显示数据库中的数据                        Console WriteLine( 显示数据库中的数据 );                        while(MyDataReader Read())                        {                            Console WriteLine( 姓名:{ } 年龄:{ } MyDataReader GetValue( ) MyDataReader GetValue( ));                        }                        MyDataReader Close();                    }                    catch (Exception ex)                    {                        Console WriteLine( { } ex ToString());                    }                    finally                    {                        MyCon Close();                        MyCon Close();                    }                    Console ReadLine();                }            }        }

lishixinzhi/Article/program/net/201311/11905  
永远跟党走
  • 如果你觉得本站很棒,可以通过扫码支付打赏哦!

    • 微信收款码
    • 支付宝收款码