C# ado.net 测试带实例名的sqlserver

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;

namespace HelloWorld
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Hello中国");

            SqlConnection conn = new SqlConnection(@"server=sm-pc,1433\sql2008;uid=sa;pwd=Admin12345;database=dbname");
            SqlCommand cmd = new SqlCommand("SELECT * FROM user where user_code LIKE 'ad%'", conn);
            conn.Open();
            SqlDataReader dr =  cmd.ExecuteReader();
            while(dr.Read()){
                string acctId = dr["u_id"].ToString();
                Console.WriteLine(acctId);
            }
            conn.Close();
            Console.ReadKey();
        }
    }
}

  

 http://www.connectionstrings.com/sql-server-2008

 

 

 

posted @ 2013-03-16 01:16  庚武  Views(280)  Comments(0Edit  收藏  举报