zoukankan      html  css  js  c++  java
  • 使用ado.net访问数据库

    属性 说明
    ConnectionString 设置/获取应用程序连接字符串
    方法 说明
     void open()

    使用ConnectionString属性所指定的设置打开数据库连接

    void Close() 关闭与数据库的连接

    2.定义连接字串

    string sqlcon="Data Source=.;Initial Calalog=MySchool;User ID=sa;Pwd=.";

    2.2创建connection对象

    SqlConnection con=new SqlConnection(sqlcon);

    3.处理异常时的1

    try
       {
        //可能发生异常的代码
        con.Open();
       }
       catch(Exception ex)
       {
        //捕获异常
        Console.WriteLine(ex);
       }
       finally
       {
        con.Close();
        //永远都会被执行
       }

    5.Command
    Command cmdUser=new Command();
    cmdUser.CommandText="SELECT UserName,UserAddr FROM tblUser";
    cmdUser.Connection=cn;
    1.打开数据库连接
    cn.Open();
    reader=cmdUser.ExecuteReader();
    2.关闭数据库连接
    reader.Close();
    cn.Close();

  • 相关阅读:
    网站添加背景音乐
    解决项目上的红色感叹号
    1.12那些年你不知道的爬虫面试题
    1.11you-get 视频爬取
    1.10pytesseract
    1.9Pyppeteer
    1.8request-html
    1.7XPath
    1.6Selenium XPath
    1.5cookies
  • 原文地址:https://www.cnblogs.com/s122/p/7755490.html
Copyright © 2011-2022 走看看