0

I have written a class which has the fields name,Reg_No,etc.

    public int Reg_No { get; set; }
    public string Name { get; set; }

my case reg no will be like " 1", "be01 " in mongo db the field type will be int32 for value 1 and string for be01

in my class i have tried both string and int data type, I' am facing the following error. An error occurred while de serializing the Reg_No property of class Mongo_Studentattendance: Input string was not in a correct format.

Please help me to solve this and guide me to proceed further.

slfan
  • 8,950
  • 115
  • 65
  • 78
siva
  • 243
  • 2
  • 6
  • 11
  • I'm not entirely clear on your data needs. You want one field to be strongly typed somehow to two different data types (string and Int32)? – WiredPrairie Feb 14 '13 at 15:56
  • Hi WiredPrairie, i have imported data from sql via csv to mongodb, in that Reg_No has values like numeric and string, when I try to map with a class with type string for the field Reg_No, getting error input string was not in a correct format. – siva Feb 15 '13 at 05:26
  • What should i do to make the field type as string for Reg_No in mongodb. – siva Feb 15 '13 at 05:33
  • Invert [this](http://stackoverflow.com/questions/14861988/mongo-convert-all-numeric-fields-that-are-stored-as-string/14862762#14862762) logic. – WiredPrairie Feb 15 '13 at 11:41
  • I tried this [link](http://stackoverflow.com/questions/4973095/mongodb-how-to-change-the-type-of-a-field) answer given by Simone it worked. thanks @WiredPrairie . – siva Feb 15 '13 at 14:07

1 Answers1

0

just change the data type of your property Reg_No to dynamic. your reg_no property should be as shown here

    public dynamic Reg_No { get; set; }
Ali
  • 1
  • 1