Click here to Skip to main content
16,004,977 members
Home / Discussions / C#
   

C#

 
GeneralRe: Equivalent of SetItemData, GetItemData in C# Pin
Heath Stewart21-Jun-04 3:00
protectorHeath Stewart21-Jun-04 3:00 
GeneralRe: Equivalent of SetItemData, GetItemData in C# Pin
Md Saleem Navalur21-Jun-04 2:42
Md Saleem Navalur21-Jun-04 2:42 
GeneralRetrieving POP3 message Pin
ronin177016-Jun-04 17:19
ronin177016-Jun-04 17:19 
GeneralRe: Retrieving POP3 message Pin
palbano16-Jun-04 18:57
palbano16-Jun-04 18:57 
GeneralRe: Retrieving POP3 message Pin
Heath Stewart16-Jun-04 21:31
protectorHeath Stewart16-Jun-04 21:31 
Questionhow to scrolling through "stacked" images? Pin
ABean16-Jun-04 15:38
ABean16-Jun-04 15:38 
AnswerRe: how to scrolling through "stacked" images? Pin
Heath Stewart16-Jun-04 21:23
protectorHeath Stewart16-Jun-04 21:23 
GeneralExecption in db command..please help Pin
link_7916-Jun-04 12:24
link_7916-Jun-04 12:24 
Hi guys,

below is a code snippet that is raising a cast exception when I attempt to pull out data from a row reader.

// setup

command = "SELECT IDENT_CURRENT ( @tableName )";
getLastIdentityCommand = new SqlCommand(command);
getLastIdentityCommand.Parameters.Add("@tableName", SqlDbType.VarChar, 20);

....

// in my prepare ftn routine , I set the connection and table name

getLastIdentityCommand.Connection = con;
getLastIdentityCommand.Parameters[0].Value = tableName;
getLastIdentityCommand.Prepare();

...

// finally I use the damn thing elsewhere

SqlDataReader rowReader = getLastIdentityCommand.ExecuteReader();
long lastInsertId = -1; // I was using 'int' before but problem still remains
if (rowReader.Read())
lastInsertId = rowReader.GetInt64(0); // causes cast exception
...

Things to NOTE:
1) A row is inserted into a table X with identity set - identity column is of type bigint, before the problematic db command is issued

2) I have even tried using the "SELECT @@identity" syntax in the select statement without a table name, and tried extracting the id generated as follows :

int lastInsertId = (int)getLastIdentityCommand.ExecuteScalar();

3) I have even tried rowReader.GetInt32(0); and still the same exception.

Is an identity a special type and NOT and integer?? How can I get this value
since I need to update a 2nd table with it.

ANy and all help will be very appreciated.

Thanks.
GeneralNever mind Pin
link_7916-Jun-04 12:58
link_7916-Jun-04 12:58 
Generalcustom metadata editor using c#.net Pin
abhishk2001@yahoo.com16-Jun-04 11:53
abhishk2001@yahoo.com16-Jun-04 11:53 
GeneralRe: custom metadata editor using c#.net Pin
link_7916-Jun-04 12:36
link_7916-Jun-04 12:36 
GeneralRe: custom metadata editor using c#.net Pin
Heath Stewart16-Jun-04 13:56
protectorHeath Stewart16-Jun-04 13:56 
GeneralArcCatalog Custom metadata editor using c#.net Pin
abhishk2001@yahoo.com16-Jun-04 11:48
abhishk2001@yahoo.com16-Jun-04 11:48 
GeneralRe: ArcCatalog Custom metadata editor using c#.net Pin
Heath Stewart16-Jun-04 13:52
protectorHeath Stewart16-Jun-04 13:52 
GeneralArcCatalog Custom metadata editor using c#.net Pin
abhishk2001@yahoo.com16-Jun-04 11:45
abhishk2001@yahoo.com16-Jun-04 11:45 
GeneralUTC time to localtime Pin
Anonymous16-Jun-04 11:14
Anonymous16-Jun-04 11:14 
GeneralRe: UTC time to localtime Pin
Heath Stewart16-Jun-04 13:49
protectorHeath Stewart16-Jun-04 13:49 
Generalmy mouse up event only fires once Pin
robmays16-Jun-04 10:57
robmays16-Jun-04 10:57 
GeneralRe: my mouse up event only fires once Pin
Heath Stewart16-Jun-04 13:45
protectorHeath Stewart16-Jun-04 13:45 
GeneralIs there a "TextFolding Control"! Pin
BrandonXander16-Jun-04 10:46
BrandonXander16-Jun-04 10:46 
GeneralRe: Is there a "TextFolding Control"! Pin
xuhx16-Jun-04 17:22
xuhx16-Jun-04 17:22 
GeneralWinControls and System.Management Pin
Wender Oliveira16-Jun-04 8:39
Wender Oliveira16-Jun-04 8:39 
GeneralRe: WinControls and System.Management Pin
Dave Kreskowiak16-Jun-04 9:14
mveDave Kreskowiak16-Jun-04 9:14 
GeneralNet.Socket problem Pin
tweakk16-Jun-04 8:29
tweakk16-Jun-04 8:29 
GeneralRe: Net.Socket problem Pin
Heath Stewart16-Jun-04 10:17
protectorHeath Stewart16-Jun-04 10:17 

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.