System.InvalidCastException : Object cannot be cast from DBNull to other types

From: M(dot) Bilgehan İMAMOĞLU <bilgehanbey(at)gmail(dot)com>
To: <pgsql-bugs(at)postgresql(dot)org>
Subject: System.InvalidCastException : Object cannot be cast from DBNull to other types
Date: 2005-09-26 07:06:51
Message-ID: 43379ec4.411aab92.2f72.ffff97ab@mx.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

Hi,

I write a program with C#.

When i try to execute SQL query with pgAdmin III Query tool, i can see all
data successfully.

But i get "System.InvalidCastException : Object cannot be cast from DBNull
to other types" error when execute sql query with c# codes.

I can see BASLIK,FO1,FO2,FO3 and FO4 coluns with query in C#.

But other columns have NULL value.

My code is like this;

string _TEKLIF_ALANI = null;

switch(cmb_birim_secim.SelectedItem.Value)

{

case "1":

_TEKLIF_ALANI = "BIRIM_TEKLIF";

break;

case "2":

_TEKLIF_ALANI = "SAYMAN_TEKLIF";

break;

case "3":

_TEKLIF_ALANI = "BASKAN_TEKLIF";

break;

case "4":

_TEKLIF_ALANI = "ENCUMEN_TEKLIF";

break;

case "5":

_TEKLIF_ALANI = "KOMISYON_TEKLIF";

break;

case "6":

_TEKLIF_ALANI = "KESIN_TEKLIF";

break;

}

string command = null;

command = "SELECT \"KURUMSAL\".\"BASLIK\" AS \"BIRIM_ADI\",CASE WHEN
to_number(\"FONKSIYONEL\".\"KOD_1\",'9999')>0 THEN \"FONKSIYONEL\".\"KOD_1\"
ELSE '&nbsp;' END AS \"FO1\",CASE WHEN
to_number(\"FONKSIYONEL\".\"KOD_2\",'9999')>0 THEN \"FONKSIYONEL\".\"KOD_2\"
ELSE '&nbsp;' END AS \"FO2\",CASE WHEN
to_number(\"FONKSIYONEL\".\"KOD_3\",'9999')>0 THEN \"FONKSIYONEL\".\"KOD_3\"
ELSE '&nbsp;' END AS \"FO3\",CASE WHEN
to_number(\"FONKSIYONEL\".\"KOD_4\",'9999')>0 THEN \"FONKSIYONEL\".\"KOD_4\"
ELSE '&nbsp;' END AS \"FO4\",CASE WHEN
to_number(\"FINANSAL\".\"KOD_1\",'9999')>0 THEN \"FINANSAL\".\"KOD_1\" ELSE
'&nbsp;' END AS \"FI1\",CASE WHEN
to_number(\"EKONOMIK_GIDER\".\"KOD_1\",'9999')>0 THEN
\"EKONOMIK_GIDER\".\"KOD_1\" ELSE '&nbsp;' END AS \"E1\",CASE WHEN
to_number(\"EKONOMIK_GIDER\".\"KOD_2\",'9999')>0 THEN
\"EKONOMIK_GIDER\".\"KOD_2\" ELSE '&nbsp;' END AS \"E2\",CASE WHEN
to_number(\"EKONOMIK_GIDER\".\"KOD_3\",'9999')>0 THEN
\"EKONOMIK_GIDER\".\"KOD_3\" ELSE '&nbsp;' END AS \"E3\",CASE WHEN
to_number(\"EKONOMIK_GIDER\".\"KOD_4\",'9999')>0 THEN
\"EKONOMIK_GIDER\".\"KOD_4\" ELSE '&nbsp;' END AS
\"E4\",\"EKONOMIK_GIDER\".\"BASLIK\" AS \"ACIKLAMA\",\"GIDER_BUTCESI\".\"" +
_TEKLIF_ALANI + "\" AS \"TEKLIF\",trim(both ' ' from
to_char(\"GIDER_BUTCESI\".\"GIDER_ID\",'9999')) || '&secim=" +
cmb_birim_secim.SelectedItem.Value + "' AS \"BUTCE_ID\" FROM
\"KURUMSAL\",\"FONKSIYONEL\",\"FINANSAL\",\"EKONOMIK_GIDER\",\"GIDER_BUTCESI
\" WHERE \"GIDER_BUTCESI\".\"KURUMSAL_ID\"=" + _kurum_kodu._getID + " AND
\"GIDER_BUTCESI\".\"KURUMSAL_ID\"=\"KURUMSAL\".\"KURUMSAL_ID\" AND
\"GIDER_BUTCESI\".\"FONKSIYONEL_ID\"=\"FONKSIYONEL\".\"FONKSIYONEL_ID\" AND
\"GIDER_BUTCESI\".\"FINANSAL_ID\"=\"FINANSAL\".\"FINANSAL_ID\" AND
\"GIDER_BUTCESI\".\"EKONOMIK_ID\"=\"EKONOMIK_GIDER\".\"EKONOMIK_ID\" AND
\"GIDER_BUTCESI\".\"BIRIM_TEKLIF\">0 ORDER BY
\"FONKSIYONEL\".\"KOD_1\",\"FONKSIYONEL\".\"KOD_2\",\"FONKSIYONEL\".\"KOD_3\
",\"FONKSIYONEL\".\"KOD_4\",\"FINANSAL\".\"KOD_1\",\"EKONOMIK_GIDER\".\"KOD_
1\",";

command += "\"EKONOMIK_GIDER\".\"KOD_2\",";

command += "\"EKONOMIK_GIDER\".\"KOD_3\"";

command += ",\"EKONOMIK_GIDER\".\"KOD_4\"";

DataTable dt = GenelClass.SelectSonucu(command);

double _PARA = 0;

for(int i=0; i<dt.Rows.Count; i++)

_PARA += Convert.ToDouble(dt.Rows[i]["TEKLIF"]);

lbl_toplam.Text = Convert.ToString(_PARA) + " YTL";

rptr_butce_fisi.DataSource = dt;

rptr_butce_fisi.DataBind();

thanks ,

Bilgehan

Browse pgsql-bugs by date

  From Date Subject
Next Message wally 2005-09-26 09:08:27 BUG #1908: sql support chinese char error
Previous Message Michael Kappler 2005-09-26 02:49:11 BUG #1907: problem with function return as integer[]