Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Converted bigint to varchar in MSSQL

I have this column ContactNo and others like this e-g FaxNo etc.

Problem is in MSSQL these columns were defined as bigint, and I changed them to varchar in MSSQL using Management Studio:

enter image description here

The only reason I want to change it from int to varchar/string so that I can have "0" at start. As in int I can't put "0" in the beginning.

I thought I also need to do change in dataset so I also updated the dataset in WPF. In Data Sets Changed the same column for same table from System.Int64 to System.String

enter image description here

But even I still get this error:

Specified Cast is not valid

enter image description here

It works fine if I change back types to whatever types they were before, but those big int types don't allow zeros.

When I do debugging, see this yellow highlight. After this it directly jumps to exception error:

enter image description here

Update 1

enter image description here

enter image description here

like image 649
Sizzling Code Avatar asked Aug 18 '15 06:08

Sizzling Code


2 Answers

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.

like image 113
user3690202 Avatar answered Sep 18 '22 20:09

user3690202


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.

like image 41
Pradeep Kumar Avatar answered Sep 17 '22 20:09

Pradeep Kumar