Click here to Skip to main content
15,867,453 members
Home / Discussions / C#
   

C#

 
GeneralRe: how to take a table name from a text box! Pin
AHSAN1115-Jan-12 2:18
professionalAHSAN1115-Jan-12 2:18 
Questionwhen i delete my program (in C#) the database still exists - how to delete him ? Pin
goldsoft3-Jan-12 4:51
goldsoft3-Jan-12 4:51 
AnswerRe: when i delete my program (in C#) the database still exists - how to delete him ? Pin
Richard Andrew x643-Jan-12 6:00
professionalRichard Andrew x643-Jan-12 6:00 
GeneralRe: when i delete my program (in C#) the database still exists - how to delete him ? Pin
Gali19783-Jan-12 9:33
Gali19783-Jan-12 9:33 
GeneralRe: when i delete my program (in C#) the database still exists - how to delete him ? Pin
Richard Andrew x643-Jan-12 9:36
professionalRichard Andrew x643-Jan-12 9:36 
AnswerRe: when i delete my program (in C#) the database still exists - how to delete him ? Pin
PIEBALDconsult3-Jan-12 7:39
mvePIEBALDconsult3-Jan-12 7:39 
GeneralRe: when i delete my program (in C#) the database still exists - how to delete him ? Pin
Paladin20003-Jan-12 9:49
Paladin20003-Jan-12 9:49 
QuestionOdbcDataReader calling IsDBNull changes the behaviour of Get methods Pin
__John_3-Jan-12 3:16
__John_3-Jan-12 3: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 3:46
kevinnicol3-Jan-12 3:46 
GeneralRe: OdbcDataReader calling IsDBNull changes the behaviour of Get methods Pin
__John_3-Jan-12 4:10
__John_3-Jan-12 4:10 
AnswerRe: OdbcDataReader calling IsDBNull changes the behaviour of Get methods Pin
Dan Mos3-Jan-12 4:18
Dan Mos3-Jan-12 4:18 
GeneralRe: OdbcDataReader calling IsDBNull changes the behaviour of Get methods Pin
__John_3-Jan-12 4:24
__John_3-Jan-12 4:24 
GeneralRe: OdbcDataReader calling IsDBNull changes the behaviour of Get methods Pin
Dan Mos3-Jan-12 4:26
Dan Mos3-Jan-12 4:26 
GeneralRe: OdbcDataReader calling IsDBNull changes the behaviour of Get methods Pin
__John_3-Jan-12 4:35
__John_3-Jan-12 4:35 
GeneralRe: OdbcDataReader calling IsDBNull changes the behaviour of Get methods Pin
Dan Mos3-Jan-12 4:41
Dan Mos3-Jan-12 4:41 
GeneralRe: OdbcDataReader calling IsDBNull changes the behaviour of Get methods Pin
__John_3-Jan-12 5:22
__John_3-Jan-12 5:22 
AnswerRe: OdbcDataReader calling IsDBNull changes the behaviour of Get methods Pin
Dan Mos3-Jan-12 7:08
Dan Mos3-Jan-12 7:08 
AnswerRe: OdbcDataReader calling IsDBNull changes the behaviour of Get methods Pin
PIEBALDconsult3-Jan-12 4:00
mvePIEBALDconsult3-Jan-12 4:00 
AnswerRe: OdbcDataReader calling IsDBNull changes the behaviour of Get methods Pin
Dan Mos3-Jan-12 4:31
Dan Mos3-Jan-12 4:31 
GeneralRe: OdbcDataReader calling IsDBNull changes the behaviour of Get methods Pin
__John_3-Jan-12 4:38
__John_3-Jan-12 4:38 
GeneralRe: OdbcDataReader calling IsDBNull changes the behaviour of Get methods Pin
Dan Mos3-Jan-12 4:44
Dan Mos3-Jan-12 4:44 
GeneralRe: OdbcDataReader calling IsDBNull changes the behaviour of Get methods Pin
__John_3-Jan-12 4:58
__John_3-Jan-12 4:58 
GeneralRe: OdbcDataReader calling IsDBNull changes the behaviour of Get methods Pin
Dan Mos3-Jan-12 5:06
Dan Mos3-Jan-12 5:06 
GeneralRe: OdbcDataReader calling IsDBNull changes the behaviour of Get methods Pin
Dan Mos3-Jan-12 4:53
Dan Mos3-Jan-12 4:53 
GeneralRe: OdbcDataReader calling IsDBNull changes the behaviour of Get methods Pin
__John_3-Jan-12 5:02
__John_3-Jan-12 5: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.