I just started to touch VB.NET.
I would like to know why this happens.
[]
Display the value surrendered as a String as a String
[Current]
The value surrendered as a String is displayed as an Integer
Dim dt As DataTable 'DataGridView content is already stored in dt
'"0000000001"
Dim CustomerCode As String = String.Format ("{0: D10}", 1)
'1 (Integer)
dt.Rows (0) ("CUSTOMERCODE") = CustomerCode
As mentioned above, it should be entered as the string type "0000000001", but it will actually be entered as the numeric type "1".
Dim dt As DataTable 'DataGridView content is already stored in dt
'"000000001_A"
CustomerCode = String.Format ("{0: D10}", 1)&"_A"
If i do the above, you will end up with a type error.
The above is the one that was entered manually into the empty grid from the beginning.
DB → DataGridView → DataTable → DB
When processing in the order of
Does the data that should have been surrendered by String become Integer because the column manually edited when bringing information from DB is Integer type?
If all of the grid's manually entered data is only numbers, will it be considered an Integer type, and will zero-filled data in String.Format be converted to Integer?
-
Answer # 1
-
Answer # 2
option strict off Isn't it?
-
Answer # 3
What is the type of CUSTOMERCODE column in DataTable?
Look at what dt.Columns (CUSTOMERCODE) .DataType looks like.
(Or you can check the type notation with a string if you use dt.Columns (CUSTOMERCODE) .DataType.ToString.)
If it is a numeric type, it is treated as a numeric value, and the zero padding is also removed.If you do the above, it will be thrown back as a type error.
means that the column type is a numeric system such as Integer.
To avoid this,
-When getting the original DataTable, it becomes the formatted String type.
-Format the target column in DataGridView.
Reference: Specify the format (format) of the text to be displayed in the DataGridView cell
https://dobon.net/vb/dotnet/datagridview/format.htmlHowever, if you think that the target column of the original DB is a numeric value and the value edited with the grid is returned to the DB, it is better to format the target column with the latter DataGridView think.
Related articles
- java - when converting an integer to a string, i say "" "+ num"
- i want to know the reason for converting the type again after the processing (intmax_t) num that cannot be understood by c langu
- C ++ example of hex string conversion to int integer value
- Python string, integer, and float conversion examples
- Method for converting numeric string of scientific notation to decimal type
- Java judgment string is a positive integer instance
- Java method to determine whether a string is an integer or a floating point number
- Python hex integer and ASCii encoded string mutual conversion method
- Python string and integer conversion method
- Integer to string method in Golang
- Methods for converting byte [], String, Hex strings in Java
- An instance of String [] converted to an integer array Int []
- The difference between Perl string comparison and integer comparison
- String to Integer and Implementation of MyAtoi Method in Java
- Method for converting array in JS to JSON format string
- Talking about the reason why string has methods in JavaScript
- Method for converting html string into jquery dom object in javascript
- Method for converting string to json object and taking value in python
- Example of converting int and string data types in js
- Solution to error when converting string data type to spark rdd
It seems that the column type of DataTable is Integer type. A String type should be as expected. Look at the image below.