[SQL] Get Date by SqlDataReader

string connectString = "Data Source=localhost;Initial Catalog=master;Persist Security Info=True;User ID=bitty;Password=020479979";
string queryString = "SELECT [id],[test] FROM [master].[dbo].[test]";
SqlConnection myConnection = new SqlConnection(connectString);
myConnection.Open();
SqlCommand myCommand = new SqlCommand(queryString, myConnection);
SqlDataReader myReader = myCommand.ExecuteReader();
while (myReader.Read())
{
Response.Write(myReader.GetInt32(0) + myReader.GetString(1));
}
myReader.Close();
myConnection.Close();

沒有留言: