【问题标题】:{"Invalid object name 'ICCSS.mdf.TblCustomers'."}{“无效的对象名称'ICCSS.mdf.TblCustomers'。”}
【发布时间】:2018-02-27 10:56:51
【问题描述】:

当我运行我尝试从 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;

【问题讨论】:

  • 我在运行程序时遇到此错误,我曾尝试直接从 sql server 运行程序,但当我使用 mdf 时它可以工作。它给了我那个错误

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


【解决方案1】:

这种方式不要使用全限定名,直接使用TblCustomers即可:

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

然后,你会得到另一个错误,列 State 不能在没有聚合函数的情况下使用,或者它应该包含在 group by 中。可能你只需要使用DISTINCT 而不是GROUP BY

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-05-17
    • 2018-06-15
    • 1970-01-01
    • 2015-02-06
    • 2015-04-10
    相关资源
    最近更新 更多