Click here to Skip to main content
15,557,928 members
Home / Discussions / C#
   

C#

 
GeneralRe: how to take a table name from a text box! Pin
AHSAN1115-Jan-12 3:18
professionalAHSAN1115-Jan-12 3:18 
Questionwhen i delete my program (in C#) the database still exists - how to delete him ? Pin
goldsoft3-Jan-12 5:51
goldsoft3-Jan-12 5:51 
AnswerRe: when i delete my program (in C#) the database still exists - how to delete him ? Pin
Richard Andrew x643-Jan-12 7:00
professionalRichard Andrew x643-Jan-12 7:00 
GeneralRe: when i delete my program (in C#) the database still exists - how to delete him ? Pin
Gali19783-Jan-12 10:33
Gali19783-Jan-12 10:33 
GeneralRe: when i delete my program (in C#) the database still exists - how to delete him ? Pin
Richard Andrew x643-Jan-12 10:36
professionalRichard Andrew x643-Jan-12 10:36 
AnswerRe: when i delete my program (in C#) the database still exists - how to delete him ? Pin
PIEBALDconsult3-Jan-12 8:39
professionalPIEBALDconsult3-Jan-12 8:39 
GeneralRe: when i delete my program (in C#) the database still exists - how to delete him ? Pin
Paladin20003-Jan-12 10:49
Paladin20003-Jan-12 10:49 
QuestionOdbcDataReader calling IsDBNull changes the behaviour of Get methods Pin
__John_3-Jan-12 4:16
__John_3-Jan-12 4:16 
Hi,

If I do...

C#
int nColName   = odbcDataReader.GetOrdinal(@"name");
int nColNumber = odbcDataReader.GetOrdinal(@"iq");

while (odbcDataReader.Read())
{
    string strName = odbcDataReader.GetString(nColNumber);
    int nNumber = odbcDataReader.GetInt32(nColNumber);
}


GetString() succeeds.
GetInt32() throws an exception... [System.InvalidCastException] = {"Specified cast is not valid."}

However if I do...

C#
int nColName   = odbcDataReader.GetOrdinal(@"name");
int nColNumber = odbcDataReader.GetOrdinal(@"iq");

while (odbcDataReader.Read())
{
    odbcDataReader.IsDBNull(nColNumber);

    int nNumber = odbcDataReader.GetInt32(nColNumber);

    string strNumber = odbcDataReader.GetString(nColNumber);

}


Now GetInt32() succeeds.
And GetString() throws an exception... [System.InvalidCastException] = {"Unable to cast object of type 'System.Int32' to type 'System.String'."}

FYI: The column in question 'IQ' is of type 'int'.

It seems that calling IsDBNull() first, changes the behaviour of the Get methods.

Can anyone explain what is going on?

Thanks - John.
AnswerRe: OdbcDataReader calling IsDBNull changes the behaviour of Get methods Pin
kevinnicol3-Jan-12 4:46
kevinnicol3-Jan-12 4:46 
GeneralRe: OdbcDataReader calling IsDBNull changes the behaviour of Get methods Pin
__John_3-Jan-12 5:10
__John_3-Jan-12 5:10 
AnswerRe: OdbcDataReader calling IsDBNull changes the behaviour of Get methods Pin
Dan Mos3-Jan-12 5:18
Dan Mos3-Jan-12 5:18 
GeneralRe: OdbcDataReader calling IsDBNull changes the behaviour of Get methods Pin
__John_3-Jan-12 5:24
__John_3-Jan-12 5:24 
GeneralRe: OdbcDataReader calling IsDBNull changes the behaviour of Get methods Pin
Dan Mos3-Jan-12 5:26
Dan Mos3-Jan-12 5:26 
GeneralRe: OdbcDataReader calling IsDBNull changes the behaviour of Get methods Pin
__John_3-Jan-12 5:35
__John_3-Jan-12 5:35 
GeneralRe: OdbcDataReader calling IsDBNull changes the behaviour of Get methods Pin
Dan Mos3-Jan-12 5:41
Dan Mos3-Jan-12 5:41 
GeneralRe: OdbcDataReader calling IsDBNull changes the behaviour of Get methods Pin
__John_3-Jan-12 6:22
__John_3-Jan-12 6:22 
AnswerRe: OdbcDataReader calling IsDBNull changes the behaviour of Get methods Pin
Dan Mos3-Jan-12 8:08
Dan Mos3-Jan-12 8:08 
AnswerRe: OdbcDataReader calling IsDBNull changes the behaviour of Get methods Pin
PIEBALDconsult3-Jan-12 5:00
professionalPIEBALDconsult3-Jan-12 5:00 
AnswerRe: OdbcDataReader calling IsDBNull changes the behaviour of Get methods Pin
Dan Mos3-Jan-12 5:31
Dan Mos3-Jan-12 5:31 
GeneralRe: OdbcDataReader calling IsDBNull changes the behaviour of Get methods Pin
__John_3-Jan-12 5:38
__John_3-Jan-12 5:38 
GeneralRe: OdbcDataReader calling IsDBNull changes the behaviour of Get methods Pin
Dan Mos3-Jan-12 5:44
Dan Mos3-Jan-12 5:44 
GeneralRe: OdbcDataReader calling IsDBNull changes the behaviour of Get methods Pin
__John_3-Jan-12 5:58
__John_3-Jan-12 5:58 
GeneralRe: OdbcDataReader calling IsDBNull changes the behaviour of Get methods Pin
Dan Mos3-Jan-12 6:06
Dan Mos3-Jan-12 6:06 
GeneralRe: OdbcDataReader calling IsDBNull changes the behaviour of Get methods Pin
Dan Mos3-Jan-12 5:53
Dan Mos3-Jan-12 5:53 
GeneralRe: OdbcDataReader calling IsDBNull changes the behaviour of Get methods Pin
__John_3-Jan-12 6:02
__John_3-Jan-12 6:02 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.