简单ADO.NET
static void Main(string[] args)
{
using (SqlConnection connection = new SqlConnection(CSharpTest.Properties.Settings.Default.Database1ConnectionString))
{
SqlCommand sqlCommand = new SqlCommand();
string sqlText = "select username from mytable where id=1";
sqlCommand.CommandText = sqlText;
sqlCommand.Connection = connection;
connection.Open();
string userNameDB = Convert.ToString(sqlCommand.ExecuteScalar());
Console.WriteLine(userNameDB);
sqlCommand.Dispose();
}
}