Reputation: 3484
I am trying to convert text box values in my C# application to Numeric data format saved in an MS Access database. There seems to be a couple of ways to convert text to number. For instance, Convert.ToInt32, Convert.ToInt16, Convert.ToInt64. They all seem to work. I am developing the application on a 64 bit machine running Windows 8.1 and I have no idea which type of conversion I should use. How can the following snippet be updated to adapt it to different versions of Windows?
oleCmd.Parameters.Add("@partyID", OleDbType.Numeric).Value =
Convert.ToInt32(comboBoxWorkParty.SelectedValue.ToString());
oleCmd.Parameters.Add("@projectTypeID", OleDbType.Numeric).Value =
Convert.ToInt32(comboBoxProjectType.SelectedValue.ToString());
Upvotes: 1
Views: 1109
Reputation: 123654
Regardless of whether you are using the 64-bit version or the 32-bit version of the Access Database Engine:
Long Integer
field in an Access database corresponds to Int32
, and Integer
field in an Access database corresponds to Int16
.Upvotes: 2
Reputation: 6357
Bitness of your OS has nothing to do with the bitness of integer you want to store. It only depends on the accepted range of integer values of your ComboBox elements. For all practical purposes, you should be good with converting to Int32
.
Upvotes: 2