zoukankan      html  css  js  c++  java
  • winForm连接数据库(sqlserver2005)

    帮同学搞个课程设计winform连接sqlserver2005

    具体方法:

    .添加App.config文件

    2.在App.config文件中添加节点

    <?xml version="1.0" encoding="utf-8" ?>
    <configuration>
    <appSettings>
        <add key="connString" value="Data Source=LIBL;Initial Catalog=MyTest;User ID=sa;Password=sa"></add>
    </appSettings>
    </configuration>

    3.在项目Reference中添加引用 System.configuration

    在文件中 添加引用 using System.configuration;

                                    using System.Data.SqlClient;

    4.获取App.config中的连接字符串

        public string ConnString = System.Configuration.ConfigurationManager.AppSettings["connString"];

    5.连接数据库,读取数据

    SqlConnection conn = new SqlConnection(ConnString);
                string strSql = "SELECT * FROM Basetb";
                SqlCommand cmd = new SqlCommand();
                cmd.CommandText = strSql;
                cmd.Connection = conn;
                conn.Open();
                SqlDataReader dr = cmd.ExecuteReader();
                if (dr.HasRows)
                {
                    while (dr.Read())
                    {
                        this.textBox1.Text = dr[0].ToString();
                    }
                }
                conn.Close();

    文章来自:http://hi.baidu.com/lili_weiwei/blog/item/8f86c6a9895586bdca130c1b.html

  • 相关阅读:
    解决span中的内容不换行
    javascript中apply、call和bind的区别
    vuex及其属性应用
    55.动态加载Html
    58.圆角图片
    57.动态添加子View(Java/XML两种方式)
    56.Java与js交互
    59.仿微信的图片浏览器
    64.判断当前线程是否是主线程
    61.自定义Indicator
  • 原文地址:https://www.cnblogs.com/hpuCode/p/2294986.html
Copyright © 2011-2022 走看看