Converted bigint to varchar in MSSQL

I suspect you have a field in AgentAccount which you haven't updated to be a string, and it is still an int. As such, the cast is failing. Select AgentAccount in code, hit F12 to jump to the definition, and then update the field to be a string. Then everything should work.


Since you have made changes in the underlying database, all you need to do in your program is regenerate your typed dataset code. That should solve all such issues.

Try this:

Close all the windows and open Dataset1.xsd (designer). Do something on the designer surface that forces it to regenerate the code. Most of the times just even moving one of the tables a bit should do the trick; but if it doesn't just right-click and add a dummy adapter, then save then delete it and save again. (The intention is to make it regenerate the auto-generated code again).

Repeat the process for any more typed datasets you might have. (I see one named RMSDatabase2Dataset. xsd in the screenshot).

Finally save everything and do a full rebuild of the project.


If you want to display leading zeroes only in UI, you can use string format for bindings or you can also use converters. But if you need to save the values with leading zeroes, in Database, then it is better to change the type to varchar.

Secondly, are you using Datasets or LINQ to SQL Classes? The sample code has both it seems, I assume you are getting the data using adapters in DataClassesDataContext.AgentAccount property.

Make sure that the query returns data else you won't be able to get the exception,since there won't be any object to cast.

While doing the same steps in a simple dataset,everything works fine, coz when you modify the Dataset.ContactNo & save the file, it reflects in all the relevant places.