Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/78.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# 应用程序没有运行它在我启动后就崩溃了_C#_Sql_Sql Server_Ado.net - Fatal编程技术网

C# 应用程序没有运行它在我启动后就崩溃了

C# 应用程序没有运行它在我启动后就崩溃了,c#,sql,sql-server,ado.net,C#,Sql,Sql Server,Ado.net,我有一个问题,这是我的代码: DataTable DT1 = new DataTable(); public static DataTable DATASETRETURN(string queryString) { DataSet DS = new DataSet(); SqlDataAdapter adapter = new SqlDataAdapter { SelectCommand = new SqlCommand

我有一个问题,这是我的代码:

DataTable DT1 = new DataTable();

public static DataTable DATASETRETURN(string queryString)
{
    DataSet DS = new DataSet();

    SqlDataAdapter adapter = new SqlDataAdapter
            {
                SelectCommand = new SqlCommand(queryString, CLSERVICES.CON)
            };
    adapter.Fill(DS, "TABLE");

    return DS.Tables["TABLE"];
}

private void FE_C_HISTORIQUE_Load(object sender, EventArgs e)
{
    E_HISTORIQUE_LV_HISTORIQUE_04.Items.Clear();
    string req = "select H.NHistorique, P.Intitulle, H.QuantiteVendu, P.PrixVente,"+
                 "(P.PrixVente * H.QuantiteVendu) as PQ, H.TypeAction, H.DateAction " +
                 "from HISTORIQUE as H, PRODUIT as P" +
                 "where (P.NProduit = H.NProduit)"+
                 "order by H.NHistorique desc";
    DT1 = DATASETRETURN(req);

    for (int i = 0; i < DT1.Rows.Count; i++)
    {
        ListViewItem LV = new ListViewItem(DT2.Rows[i][0].ToString());
        LV.SubItems.Add(DT1.Rows[i][1].ToString());
        LV.SubItems.Add(DT1.Rows[i][2].ToString());
        LV.SubItems.Add(DT1.Rows[i][3].ToString());
        LV.SubItems.Add(DT1.Rows[i][4].ToString());
        LV.SubItems.Add(DT1.Rows[i][5].ToString());
        LV.SubItems.Add(DT1.Rows[i][6].ToString());

        E_HISTORIQUE_LV_HISTORIQUE_04.Items.Add(LV);
    }
} 
错误是:

System.Data.SqlClient.SqlException \P\不是可识别的表提示选项。如果要将其用作表值函数或CHANGETABLE函数的参数,请确保将数据库兼容模式设置为90


有什么解决办法吗?

由于p\u where和H.NProduit\u订单之间缺少空格而导致的问题

指定多行查询时,我更喜欢:

string req = @"
  select H.NHistorique,P.Intitulle,H.QuantiteVendu,P.PrixVente,
   (P.PrixVente*H.QuantiteVendu)as PQ,H.TypeAction,H.DateAction
  from HISTORIQUE as H, PRODUIT as P
  where(P.NProduit = H.NProduit)
  order by H.NHistorique  desc
";

这样可以减少查询中缺少新行的可能性。

某些sql字符串的结尾缺少空格。例如,…PRODUIT as PwhereP.NProduit…在调试器中的DT1=dataseturn处设置断点,并查看req包含的内容。-25年前,在ANSI-92 SQL标准中,旧样式的逗号分隔表列表样式被正确的ANSI连接语法所取代,因此不鼓励使用它谢谢@Gaber be为我提供了问题的来源。谢谢@dourHighArch我下次将尝试它:好的,谢谢,现在我知道了一个新问题的解决方案,非常感谢。
string req = @"
  select H.NHistorique,P.Intitulle,H.QuantiteVendu,P.PrixVente,
   (P.PrixVente*H.QuantiteVendu)as PQ,H.TypeAction,H.DateAction
  from HISTORIQUE as H, PRODUIT as P
  where(P.NProduit = H.NProduit)
  order by H.NHistorique  desc
";