-3

我正在尝试运行控制台应用程序(连接并读取 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();

        }
    }
4

2 回答 2

3

更改c.Model c.Yearc.Model, c.Year

于 2012-08-13T18:02:22.673 回答
3

您在这里缺少一个逗号:

string query = "SELECT c.Name, c.Model, c.Year FROM CarsCatalog c";

(在 c.Model 之后)

于 2012-08-13T18:02:35.970 回答