程序没有报错,数据库中也有数据,程序运行后就直接关闭了,为什么不输出数据呢?
using System;
using System.Data;
using System.Data.SqlClient;
namespace ConsoleApp1
{
class Program
{
static void Main(string[] args)
{
SqlConnection conn = new SqlConnection("server=wdt2019.australiasoutheast.cloudapp.azure.com;uid=s3642823;database=s3642823;pwd=abc123;");
SqlCommand query = new SqlCommand("select * from dbo.Room", conn);
SqlDataReader read;
try
{
conn.Open();
read = query.ExecuteReader();
while (read.Read())
{
Console.WriteLine("{0}",read["RoomID"]);
}
read.Close();
}
catch (SqlException se)
{
Console.WriteLine("SQL Exception: {0}", se.Message);
}
catch (Exception e)
{
Console.WriteLine("Exception: {0}", e.Message);
}
finally
{
if (conn.State == ConnectionState.Open)
{
conn.Close();
}
}
}
}
}
慕函数5213667
相关分类