{“无效的对象名称'ICCSS.mdf.TblCustomers'。”}

时间:2017-09-18 19:53:19

标签: c# asp.net sql-server asp.net-mvc linq

我运行程序时遇到此错误我尝试直接从sql server运行程序,但是当我使用mdf时。它给了我那个错误

 DataTable dt = new DataTable("VehicleSummary");
            string query = "select Country,State as 'location' from ICCSS.mdf.TblCustomers group by Country";
            SqlConnection con = new SqlConnection();
            con.ConnectionString = "Server=(localdb)\\MSSQLLocalDb;Integrated Security=true;AttachDbFileName=|DataDirectory|\\ICCSS.mdf;";
            SqlCommand cmd = new SqlCommand();
            cmd.CommandText = query;
            cmd.Connection = con;
            SqlDataAdapter da = new SqlDataAdapter(cmd);
            con.Open();
            da.Fill(dt);
            con.Close();
            var dataView = new DataView(dt);
            new Chart(width: 600, height: 400)
            .AddTitle("Chart for Growth [Column Chart]")
            //.AddSeries("Default", chartType: "column", xValue: xValue, yValues: yValue)
            //.AddSeries("Default", chartType: "Bar", xValue: xValue, yValues: yValue)
            //ChartType: "Bar","Column","","","",""
            .AddSeries("Default", chartType: "Column", xValue: dataView, xField: "Country", yValues: dataView, yFields: "location")
            .AddLegend("Summary")
            .Write("bmp");
            return null;

1 个答案:

答案 0 :(得分:0)

请勿以这种方式使用完全限定名称,只需直接使用TblCustomers

string query = "select Country,State as 'location' from TblCustomers group by Country";

然后,您将收到另一个错误,如果没有聚合函数,则无法使用列State,或者它应该包含在组中。可能只需要使用DISTINCT代替GROUP BY