我正在尝试运行控制台应用程序(连接并读取 SQL),但在“。”附近出现错误语法错误。
static void Main(string[] args)
{
string connstring = @"Data Source=Jama-Dharma\SQLEXPRESS;Initial Catalog=Cars;Integrated Security=True";
SqlConnection conn = new SqlConnection(connstring);
using (conn)
{
string query = "SELECT c.Name, c.Model c.Year FROM CarsCatalog c";
SqlCommand command = new SqlCommand(query, conn);
conn.Open();
SqlDataReader reader = command.ExecuteReader();
while (reader.Read())
{
Console.WriteLine(string.Format("{0} {1} {2}", reader.GetString(0), reader.GetString(1), reader.GetInt32(2)));
}
conn.Close();
}
}