C#连接sqlserver

using System;
using System.Threading;
using System.Threading.Tasks;
using System.Data;
using System.Data.SqlClient;

namespace ThreadTest
{
    class Program
    {
        
        static void Main()
        {
            //A a1 = new A();
            //a1.Method();
            //int a = 15, b = 10;
            //float c = a / b;
            //Console.WriteLine(c);
            //Console.ReadKey();
            SqlConnection con = new SqlConnection();
            con.ConnectionString = "server = XXX;XXX;integrated security=SSPI";
            con.Open();
            String sql = "select * from person"; // 查询语句

            SqlDataAdapter myda = new SqlDataAdapter(sql, con); // 实例化适配器

            DataTable dt = new DataTable(); // 实例化数据表
            myda.Fill(dt); // 保存数据 
            var a = dt.Rows[0]["name"].ToString();
            
            Console.WriteLine(a);
            Console.ReadKey();
        }

       
        
    }

    
}

猜你喜欢

转载自blog.csdn.net/boiled_water123/article/details/81161183