Home > Enterprise >  C# query issues returning random values
C# query issues returning random values

Time:03-18

I have a small problem. I have a query that needs to return exact text value of the field but when I run it returns random value from dataset which doesn't match. Maybe there is obvious mistake that I just don't see.

cmd.CommandText = "SELECT GlavnaK.Datum, GlavnaK.DatumK, GlavnaK.Valuta, LEFT(GlavnaK.Konto, 3) AS Konto3, GlavnaK.PStanje, GlavnaK.Duguje, GlavnaK.Potrazuje, Kontni.NazivK FROM GlavnaK, Kontni WHERE Konto=Kontni.IDKonta";                
        OleDbDataAdapter da = new OleDbDataAdapter(cmd);
        DataSet ds = new DataSet();
        da.Fill(ds, "GK_arh");

Thanks in advance.

CodePudding user response:

Adjust to hold a correct syntax for INNER JOIN:

cmd.CommandText = "SELECT GlavnaK.Datum, GlavnaK.DatumK, GlavnaK.Valuta, LEFT(GlavnaK.Konto, 3) AS Konto3, "  
    "GlavnaK.PStanje, GlavnaK.Duguje, GlavnaK.Potrazuje, Kontni.NazivK "  
    "FROM GlavnaK "  
    "INNER JOIN Kontni "   
    "ON Glavnak.Konto = Kontni.IDKonta";

CodePudding user response:

If you mean is that the return value is random, you can try add Sort.

SELECT GlavnaK.Datum, GlavnaK.DatumK, GlavnaK.Valuta, LEFT(GlavnaK.Konto, 3) AS Konto3, GlavnaK.PStanje, GlavnaK.Duguje, GlavnaK.Potrazuje, Kontni.NazivK
FROM GlavnaK, Kontni
WHERE Konto=Kontni.IDKonta
ORDER BY GlavnaK.Datum
  • Related