• C# 连接 sql server


    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Data.SqlClient;
    
    namespace ConsoleApplication4
    {
        class Program
        {
    
            static void Main(string[] args)
            {
                try
                {
                    //sqlserver身份验证
                    string sqlconn = "server=127.0.0.1;database=dingyingsi;uid=sa;pwd=Dys123456;";
                    //windows身份验证
                    //string sqlconn = "server=(local);database=keede1228;integrated security=SSPI;";
                    string select = "select id, username, password from [user]";
                    SqlConnection conn = new SqlConnection(sqlconn);
                    Console.WriteLine("33");
                    conn.Open();
                    Console.WriteLine("11");
                    SqlCommand cmd = new SqlCommand(select, conn);
                    SqlDataReader reader = cmd.ExecuteReader();
                    while (reader.Read())
                    {
                        Console.WriteLine("id:{0} username:{1} password:{2}", reader[0], reader[1], reader[2]);
                    }
                    conn.Close();
                    Console.WriteLine("22");
                    Console.ReadKey();
                }catch(Exception e){
                    Console.WriteLine(e.Message);
                    Console.ReadKey();
                }
            }
        }
    }
  • 相关阅读:
    Exchanger
    信号量Semaphore
    CountDownLatch
    Condition
    WCF接口实例介绍
    时间显示
    pymysql-execute
    python之迭代器与生成器
    python之装饰器
    python之函数
  • 原文地址:https://www.cnblogs.com/yingsi/p/3333648.html
Copyright © 2020-2023  润新知