当前位置: 代码迷 >> ASP.NET >> 谋求访问数据库源代码.简单点的
  详细解决方案

谋求访问数据库源代码.简单点的

热度:2280   发布时间:2013-02-26 00:00:00.0
寻求访问数据库源代码.简单点的
我是刚刚学习.net   大家可以给我提供点访问数据库的源代码吗?谢谢!
希望是最简单的~

------解决方案--------------------------------------------------------
string connectionString= " ";//填你的连接字符串
string queryString =
"SELECT OrderID, CustomerID FROM dbo.Orders; ";

using (SqlConnection connection =
new SqlConnection(connectionString))
{
SqlCommand command =
new SqlCommand(queryString, connection);
connection.Open();

SqlDataReader reader = command.ExecuteReader();

// Call Read before accessing data.
while (reader.Read())
{
Console.WriteLine(String.Format( "{0}, {1} ",
reader[0], reader[1]));
}

// Call Close when done reading.
reader.Close();
}
  相关解决方案