Hello. I'm trying to use SqlDataReader to return information from my database. It works fine until it comes to a datetime field. I'm getting an error saying: " Input string was not in a correct format." on the line where I'm declaring a variable to hold my field. Here is the line where the error is occuring: Dim waitDate As Date = reader.GetDateTime("WaitListDate") Can someone tell me what I'm doing wrong?

Member Avatar
Member Avatar
+0 forum 11

(int *)a why use poiunter with intger?

Member Avatar
Member Avatar
+0 forum 3

Hello all, I have not tested the code I'm posting here to see if it compiles, but I have an issue in a large codebase and I believe that this should be the simplest program to demonstrate the issue; class base { public: shared_ptr<base> clone()=0; }; typedef shared_ptr<base> baseptr; class derived : public base { public: baseptr clone(){ return baseptr(new derived);//the equiv of this compiles in my codebase, //so it should work here } }; typedef shared_ptr<derived> derivedptr; typedef vector<derivedptr> derivedList; int main(){ derivedptr der(new derived);//equivelent comiles derivedList list;//fine list.push_back(der);//works baseptr bas = der->clone();//works derivedptr der2 = der->clone();//compiler error //error …

Member Avatar
Member Avatar
+0 forum 15

I need a way to do a cast without being returned a pointer to a new address but, the same address as the original. Something like this: derivedClass something_derived; baseClass* basePointer = &something_dervived; derivedClass* derivedPointer = static_cast <derivedClass*> (basePointer); /* my problem is "derivedPointer" isnt assigned the same address as "basePointer". I need a pointer back to type "derivedClass" to "basePointer"'s address */

Member Avatar
Member Avatar
+0 forum 7

import java.util.*; public class Elway { public static void main(String r[]) { ArrayList[] ls = new ArrayList[3]; for(int i=0; i<3; i++) { ls[i] = new ArrayList(); ls[i].add("a" + i); } Object o = ls; do3(ls); for(int i=0; i<3; i++) //insert code here } static Object do3(ArrayList[] a) { for(int i=0; i<3; i++) a[i].add("e"); return a; } } The code above compiles fine with: a. `System.out.println(((Object[])o)[i] + " ")` b. `System.out.println(((ArrayList[])o)[i] + " ")` but not with c. `System.out.println(o[i] + " ")` What is the reason? When we assigned ls to o, didn't Object o become an array?

Member Avatar
Member Avatar
+0 forum 4

Given: Sour extends Blue extends Pan `Pan p4 = new Sour();` Then set of 6 new statements given and asked to choose which ones will compile. They are: 1. `Pan p5 = p4;` 2. `Pan p6 = (Blue)p4;` 3. `Blue b2 = (Blue)b4;` 4. `Blue b3 = (Sour)p4;` 5. `Sour s1 = (Blue)p4;` 6. `Sour s2 = (Sour)p4;` Answer: 5th one won't compile. Rest all will compile and run without exception. Doubt: As a beginner I have understood that LHS should be usually a super class and **RHS should be subclass if downcast not required** like shown in original statement …

Member Avatar
Member Avatar
+0 forum 6

Compiles fine. But at runtime it gives ClassCastException. My doubt is that why is it so even though st which is of type Sample1 gets casted to Sample2 and generates exception even though Sample2 IS-A Sample1.

Member Avatar
Member Avatar
+0 forum 4

Hello everyone, I am working my way through the Forger's Win32 tutorial and am on the "Creating a Simple Application" part currently. I am using C++ (instead of C in the tutorial) and the WinGW compiler. When I compile the below code I get this error: main.cpp: In function 'LRESULT WndProc(HWND, UINT, WPARAM, LPARAM)': main.cpp:26:47: error: invalid conversion from 'HGDIOBJ {aka void*}' to 'HFONT' [-fpermissive] If I change the line to a cast: hfDefault = (HFONT)GetStockObject(DEFAULT_GUI_FONT); The error changes to: undefined reference to 'GetStockObject@4' collect2: ld returned 1 exit status I have searched around on Google and haven't found a …

Member Avatar
Member Avatar
+0 forum 3

class Dog { public void bark() { System.out.println("Dog bark"); } } class Hound extends Dog { public void bark() { System.out.println("Hound bark"); } public void sniff() { System.out.println("Hound sniff"); } } public class CastingMethodCall { public static void main(String r[]) { ((Dog)new Hound()).bark(); //((Dog)new Hound()).sniff(); } } On executing above, I get o/p as "Hound bark". So it means the cast of Dog has nothing to play any role that I can safely assume, since new Hound().bark() also gives same o/p of "Hound bark". However, if I remove the comment from next line, i.e. ((Dog)new Hound()).sniff() and then execute program, …

Member Avatar
Member Avatar
+0 forum 3

I got this simple code: #include "stdio.h" #include "stdlib.h" #include "windows.h" int main(int argc, CHAR* argv[]) { HANDLE hFile = NULL; HANDLE hMapFile = NULL; LPBYTE fileView; hFile = CreateFile(argv[1],GENERIC_READ,FILE_SHARE_READ,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL); if(hFile == INVALID_HANDLE_VALUE) { printf("CreateFile function failed\n"); goto clean; } ***** hMapFile = (LPBYTE)CreateFileMapping(hFile,NULL,PAGE_READONLY,0,256,NULL);***** if(hMapFile == NULL) { printf("CreateFileMapping function failed\n"); goto clean; } fileView = MapViewOfFile(hMapFile,FILE_MAP_READ,0,0,0); if(fileView == NULL) { printf("CreateFileMapping function failed\n"); goto clean; } clean: CloseHandle(hFile); CloseHandle(hMapFile); system("PAUSE"); return 0; } And for some reason in the line that is underlined it says that I cannot convert LPVOID to LPBYTE

Member Avatar
Member Avatar
+0 forum 5

Dear knowledgeable ones. Some time ago I made a few of my routines kind of universal, and I wonder if there is any way in Delphi (My version is Delphi9) that can be used to reuse this code in example below. As you see, the two procedures are almost identical, it is just the typedeclaration that is different in the parameters passed to the procedures. Maybe it is possible to use some kind of typecasting but my experience there is limited. The code is not bad if only 2 similar blocks, I just see that it would be better with …

Member Avatar
Member Avatar
+0 forum 3

im getting the error below and I can't figure out why this isn't working. Ive looked at this for 2 days not knowing. I'm hoping a fresh set of eyes on it might help. main.c:13: warning: assignment makes pointer from integer without a cast [CODE] //HEADER FILE: #include <stdlib.h> #include <stdio.h> #define my typedef char KEY_TYPE; typedef struct { KEY_TYPE key; } DATA; typedef struct nodeTag { DATA data; struct nodeTag* link; } NODE; // PRINTLIST FUNCTION: #include "my.h" #include <stdio.h> void printList (NODE* pList) { NODE* pWalker; pWalker = pList; printf("The linked list is "); while(pWalker) { printf("%c", pWalker->data.key); …

Member Avatar
Member Avatar
+0 forum 1

I am a beginner in programming(java) and want to know, how to do typecasting in it. show me by giving examples.

Member Avatar
Member Avatar
+0 forum 1

I am trying to catch the System.InvalidCastException error. If I put a number into the calculator the program runs ok. If the calculate button is pressed with nothing in the text boxes I get the casting error Conversion from string "" to type 'Decimal' is not valid. I understand why I am getting the error. I don't know what to do about it. I want the program to dump null data and go back to waiting for input from the user. Thanks [CODE= vb.net] Private Sub btnCalculate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCalculate.Click Dim FedTaxRate = 0.13 …

Member Avatar
Member Avatar
+0 forum 2

which of the following statements is true about casting a) you must cast to convert from an interface type to a class type. b) you must cast to convert from a class type to an interface type. c) you cannot cast to convert an interface type to a class type. d) you cannot cast from a class type to an interface type. e) both a and b above are true.

Member Avatar
Member Avatar
+0 forum 1

The next code from the book "Pro-linq language itegrated query in C# 2008" gives a casting exception error on line 29. I know ToArray returns an array of objects, which are in fact of type Employee so why it generates an error? [CODE=C#]public class Employee { public int id; public string firstName; public string lastName; public static ArrayList GetEmployeesArrayList() { ArrayList al = new ArrayList(); al.Add(new Employee { id = 1, firstName = "Joe", lastName = "Rattz" }); al.Add(new Employee { id = 2, firstName = "William", lastName = "Gates" }); al.Add(new Employee { id = 3, firstName = "Anders", …

Member Avatar
Member Avatar
+0 forum 2

Here's an easy one for you experts :P What is casting and parsing? How exactly are they different? After explaining, could anyone possibly tell me how to cast/parse the various types from and to each other? (the types being: int, double, char and String) Also, in which situations would I end up using either one of these? Thanks :D

Member Avatar
Member Avatar
+0 forum 1

Hi Guys, I'm currently developing a project using WCF (hosted on local IIS) which connects to a local SQL database using LINQ to get data. My problem is that when I run the code, 9/10 times it'll fail with the "Specified Cast Is Not Valid" error, but the other 1/10 times it will return the correct value (a messagebox with the records 'name' field. The code snippets below are from my wcf datacontract/servicecontract, server and client code. There is only one record in the table im retrieving. WCF Service (IFaveoService.cs) [CODE][ServiceContract] [ServiceKnownType(typeof(SRType))] public interface IFaveoService { [OperationContract] IEnumerable<SRType> GetSRTypeByID(int srID); …

Member Avatar
Member Avatar
+0 forum 10

Well, I've been Googling for at least 30 minutes, and looking through past posts about this, but just can't seem to find an answer that works. Basically, I've got a component class that has a single method I'm trying to test out. The entity class has a private array of these components (actually, it's an array of void*, but I cast to the appropriate type when getting the component from the array). So when I call the method it looks like this: [code]((Component*)myEntity.getComponent(Base))->testFunction();[/code] This is the error I'm getting: 1>main.obj : error LNK2019: unresolved external symbol "public: __thiscall GE::Component::Component(void)" (??0Component@GE@@QAE@XZ) …

Member Avatar
Member Avatar
+0 forum 1

I am writing a model economy in which corporations (class BCorp) and persons (class BPrsn) act as agents buying and selling goods and services. I have a pool of contacts (class BContact) in which contact information is retained about each contact between agents. In a contact object I store a pointer, which may be for a BCorp or a BPrsn, so I cast it as a (double*). When I need to access a pointer, I recast it as (BCorp*) or (BPrsn*) as appropriate. However, at some point things get confused and the program ASSERTS(). When I use intellisense in debug …

Member Avatar
Member Avatar
+0 forum 6

I have two classes and one of them is inherited from the other class. Class Person - used to store first name and last name of a person. The data members are protected. Class Candidate - used to store votes of an election, and this is inherited from Person class so that I can store name of the candiadate. I have overloaded these operators in Person class : ==, !=, <, <=, >, >= I have also overloaded the same operators in Candidate class too but the definision are same because you can only use the name of the candidate …

Member Avatar
Member Avatar
+0 forum 14

Hello all, I am getting the following run-time error every time I try to run a program I've converted from Lisp to C#: [QUOTE] System.InvalidCastException was unhandled Message="Unable to cast object of type 'System.Single[]' to type 'System.Collections.Generic.List`1[System.Single]'." [/QUOTE] In the function below the problem is occurring at line 16. The datatypes are all correct and verified elsewhere, so it is not a problem of the mismatched types in the that sense. However, it appears that C# does not allow you to cast an object to a list... I hope that isn't the case, especially since that would mean me rewriting …

Member Avatar
Member Avatar
+1 forum 2

The End.