private static void sqlcon(){
SqlConnection con = new SqlConnection();
con.ConnectionString = "server=.;database=database;uid=name;pwd=password";
con.Open();//开启链接
SqlCommand com = new SqlCommand();
com.Connection = con;
com.CommandType = CommandType.Text;
string s = "select * from table_name";
com.CommandText = s;
SqlDataReader dr = com.ExecuteReader();//执行SQL语句
if (dr.HasRows){//查到数据为true,反之为false
if (dr.Read())
{
value = dr["letter"].ToString();
}
dr.Close();
}
Console.WriteLine(value);
dr.Close();//关闭执行
con.Close();//关闭数据库
}