程序沒有報(bào)錯(cuò),數(shù)據(jù)庫中也有數(shù)據(jù),程序運(yùn)行后就直接關(guān)閉了,為什么不輸出數(shù)據(jù)呢?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();? ? ? ? ? ? ? ? }? ? ? ? ? ? }? ? ? ? }? ? }}
為什么不輸出數(shù)據(jù)呢?
安小圈
2019-01-13 13:40:00