• commandbehavior > ADOnet操作数据库总结
  • ADOnet操作数据库总结

    免费下载 下载该文档 文档格式:DOC   更新时间:2008-11-01   下载次数:0   点击次数:1
    文档基本属性
    文档语言:Simplified Chinese
    文档格式:doc
    文档作者:牛洁
    关键词:
    主题:
    备注:
    点击这里显示更多文档属性
    ADO.net操作数据库总结
    一.用SqlConnection连接SQL Server
    1..加入命名空间
    using System.Data.SqlClient;
    2.连接数据库
    SqlConnection myConnection = new SqlConnection();
    myConnection.ConnectionString = "user id=sa;password=sinofindb;initial catalog=test;data source=127.0.0.1;Connect Timeout=30";
    myConnection.Open();
    改进(更通用)的方法:
    string MySqlConnection="user id=sa;password=sinofindb;Database =test;data source=127.0.0.1;Connect Timeout=30";
    SqlConnection myConnection = new SqlConnection(MySqlConnection);
    myConnection.Open();
    二.用OleDbConnection连接
    1.加入命名空间
    using System.Data.OleDb;
    2.连接sql server
    string MySqlConnection="Provider=SQLOLEDB;Data Source=localhost;Initial Catalog=test;Integrated Security=SSPI;";
    SqlConnection myConnection = new SqlConnection(MySqlConnection);
    myConnection.Open();
    3.连接Access(可通过建立.udl文件获得字符串)
    string MySqlConnection="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:db2000.mdb;
    Persist Security Info=False;
    4.连接Oracle(也可通过OracleConnection连接)
    string MySqlConnection="Provider=MSDAORA;Data Source=db; user id=sa;password=sinofindb";
    三.创建Command对象
    1.SqlCommand 构造函数
    ①初始化 SqlCommand 类的新实例.
    public SqlCommand();
    SqlCommand myCommand = new SqlCommand();
    ②初始化具有查询文本的 SqlCommand 类的新实例.public SqlCommand(string);
    String mySelectQuery = "Select * FROM mindata";
    SqlCommand myCommand = new SqlCommand(mySelectQuery);
    ③初始化具有查询文本和 SqlConnection 的SqlCommand类实例.
    Public SqlCommand(string, SqlConnection);
    String mySelectQuery = "Select * FROM mindata";
    string myConnectString = "user id=sa;password=;database=test;server=mySQLServer";
    SqlConnection myConnection = new SqlConnection(myConnectString);
    SqlCommand myCommand = new SqlCommand(mySelectQuery,myConnection);
    ④初始化具有查询文本,SqlConnection 和 Transaction 的 SqlCommand 类实例.
    public SqlCommand(string, SqlConnection, SqlTransaction);

    下一页

  • 下载地址 (推荐使用迅雷下载地址,速度快,支持断点续传)
  • 免费下载 DOC格式下载
  • 您可能感兴趣的
  • behavior  usesubmitbehavior  fluidmovebehavior  repeatbehavior  behavior可数吗  style.behavior  loadbehavior  behavior是什么意思  servicebehavior  behavior用法