苗火 Nicholas
[C#]Connect to sql server
2017-5-20 萧
using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.SqlClient;

namespace ConsoleApplication1
{
class Program
{
static void test() {
SqlConnection con = new SqlConnection();
con.ConnectionString = "server=127.0.0.1;database=wasion;user=sa;pwd=123456";
con.Open();

SqlCommand com = new SqlCommand();
com.Connection = con;
com.CommandType = CommandType.Text;
com.CommandText = "select * from ws_user";
SqlDataReader dr = com.ExecuteReader();
while (dr.Read()) {
Console.WriteLine("name:{0}\t\tpassword:{1}" , dr["name"], dr["password"]);
}
dr.Close();
con.Close();
}

static void Main(string[] args)
{
test();
Console.ReadKey();
}
}
}
发表评论:
昵称

邮件地址 (选填)

个人主页 (选填)

内容