Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/oracle/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# SqlException未处理_C#_Sql Server_Sqlexception - Fatal编程技术网

C# SqlException未处理

C# SqlException未处理,c#,sql-server,sqlexception,C#,Sql Server,Sqlexception,请给我建议,我有代码,在执行过程中会显示此异常: 未处理SqlException。无法绑定多部分标识符T.TerritoryDescription。 无法绑定多部分标识符T.TerritoryID。 无法绑定多部分标识符T.TerritoryDescription 当我在ManagementStudio中运行SQL查询时,我得到了一些结果。当我在VisualStudio中使用此脚本运行代码时,这行代码出现异常 reader = command.ExecuteReader(); 这是我的密码:

请给我建议,我有代码,在执行过程中会显示此异常:

未处理SqlException。无法绑定多部分标识符T.TerritoryDescription。 无法绑定多部分标识符T.TerritoryID。 无法绑定多部分标识符T.TerritoryDescription

当我在ManagementStudio中运行SQL查询时,我得到了一些结果。当我在VisualStudio中使用此脚本运行代码时,这行代码出现异常

reader = command.ExecuteReader();
这是我的密码:

public void databaseQuestion()
{
    SqlConnection con = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["MyConnectionString"].ConnectionString);
    SqlCommand command = 
       new SqlCommand((@"select T.TerritoryID,T.TerritoryDescription,avg(O.Freight)
                         from Employees E
                         inner join EmployeeTerritories ET on E.EmployeeID = ET.EmployeeID
                         inner join Orders O on E.EmployeeID = O.EmployeeID
                         where T.TerritoryDescription ='Bedford'
                         group by T.TerritoryID,T.TerritoryDescription,O.Freight") ,con);
    dbFile = filePath + @"\sqlFile.txt";

    SqlDataReader reader;

    con.Open();
    reader = command.ExecuteReader();

    using (StreamWriter file = new StreamWriter(dbFile, false))
    {
        while (reader.Read())
        {
            file.WriteLine(reader["T.TerritoryID"] + "\t" + reader["T.TerritoryDescription"]+ "\t" +reader["O.Freight"]);
        }
    }

    reader.Close();
    con.Close();
}     

无法绑定多部分标识符XXXX的错误。表示如果XXXX由表的别名组成,则应检查是否已为同一查询中的表定义了此别名。
在您的场景中,您使用的是一个名为T的别名,该别名从未为查询中的任何表定义过。您的雇员别名为E,订单别名为O,雇员地区别名为ET。

您的sql语句中没有别名为T的表。如果您首先在SQLServerManagementStudio中运行sql语句,则可以修复该问题。是的,看起来您没有加入表、区域或任何实际名称