Code converts the json string to table. But my problem is, it bypass the Array Chars. So only two fields are printed on the table. It kind of skips the middle field: "Chars"
Dim JsonStr As String = "[{""Name"": ""Banana Pudding"", ""Chars"": [""abc"",""xyz""],""ID"": ""143""}]"
tb = JsonConvert.DeserializeObject(Of DataTable)(JsonStr)
GridView1.DataSource = tb
GridView1.DataBind()
Your database does not support array as a string, actually I do not know any db that do the coerce for a string to array, you have to change the value of Chars to a simple type, break it and it will work.
You may test your code with a binary field instead of string in your table, you did not mention which DBMS are you using, so I can not be more specific. but using a binary field, worth a shot, try it before breaking array to simple types.
Related
Hi I am facing an issue while converting string value to integer.
Actually I am reading data from the table and there are fields like 39% and they are string data type.
Now i want to convert them into INteger datatype and load them in to another table.
I tried using select values in PDI but it is giving me error like. "Could't convert String to Integer."
Please help me in resolving this issue.
The percentage sign isn't part of the integer type in Java, so first you need to remove that character in order to make the type casting.
Add a new "Replace in string" step between the data origin and "Select values"
Double click on the new added step and on the "In stream field" select the field that needs to be cleaned
On "Search", type "%" (without the parentheses) and click Ok to close the dialog.
That should do the trick.
I have a MySQL database (5.6 Community) with a column of type bit(60). The field holds values such as 1001, 0011, etc. I am trying to pass a string of "1010" to the database through a vb.net adapter. If I use a regular query it would look like this:
insert into my_table (my_bit_field) values (b'1010');
This works and inserts the string exactly as shown but I need to use a data adapter so I can't send the query directly.
When using the data adapter in vb.net, I was getting an error saying that it was expecting a byte array. So I tried using that:
System.Text.Encoding.ASCII.GetBytes("1010")
but it just converted it to its ASCII representation of bytes (49,48,49,48).
Is there a better way to go through the data adapter and is there a way to do this?
Thanks.
In this case, you could try the following to convert your string to a byte array:
Dim bytes() As Byte = { Convert.ToByte("1010", 2) }
However, that breaks once you have more than 8 bits in your string. You could (perhaps should) break the string into byte-sized sections and convert each to a byte, such as for this question. Since you have a bit(60) column you could also cheat a little and use something like this:
Dim inputValue As String = "000100000010000000110000010000000101000001100000011100001000"
If inputValue.Length > 60 Then ' up to 64 could be supported
' Error
End If
Dim longValue As ULong = Convert.ToUInt64(inputValue, 2)
Dim bytes() As Byte = BitConverter.GetBytes(longValue)
If BitConverter.IsLittleEndian Then
Array.Reverse(bytes)
End If
This will give you the byte array that you can presumably use in your data adapter code that was not shown.
I have a MySQL InnoDB table, one of the columns is defined as double and have stored a number 16155.987841701322 but if I perform a query from VB.NET returns
16155.9878417013
From MySQL Workbench I can see all the digits in the DB, but from VB:NET i get two digit less.
Why didn't return all the digits?
I make a little code to perform conversion test
Dim OdometerDbl As Double = 16155.987841701322
Dim OdometerStr As String
OdometerStr = CStr(OdometerDbl)
After this I get 16155.987841701322 in OdometerDbl and 16155.9878417013 in OdometerStr; so is a VB.NET Double to String conversion issue.
Theres any way to get around this or a better way to convert a Double to String without losing decimals?
From the example above
OdometerStr = OdometerDbl.ToString("R")
or
OdometerStr = OdometerDbl.ToString("G17")
References:
Why Is ToString() Rounding My Double Value?
VB.NET Converting Double Value to String = Precision loss
I have a MS Access database with a column that has some strange encoding. Oddly, I am unable to copy/paste this into anything (Chrome, Word, etc), because it strips out most of the unicode characters (though not all of them). What I am wondering, is there a way to determine what type of encoding is being used here?
Somehow the program I am using is taking this column and decoding it to readable text. I converted the Access database to PostgreSQL on a Linux system, but I'm pretty sure whatever encoding is being used here did not map correctly into the PostgreSQL database. What I'm trying to do is to convert this to hex, but I cannot do it since I'm unable to copy/paste the characters out of the database.
You can open the table as a recordset. Then loop the records and convert the field to hex using a function like this:
Public Function StrToByte(ByVal strChars As String) As String
Dim abytChar() As Byte
Dim lngChar As Long
Dim strByte As String
abytChar() = StrConv(strChars, vbFromUnicode)
strByte = Space(2 * (1 + UBound(abytChar) - LBound(abytChar)))
For lngChar = LBound(abytChar) To UBound(abytChar)
Mid(strByte, 1 + 2 * lngChar) = Hex(abytChar(lngChar))
Next
StrToByte = strByte
End Function
Or create a query:
Select *, StrToByte([EncryptedFieldName]) As HexField
From tblYourTable
I created a settings file for my application, like this:
username: ProGamingHun
version: 1.0
maxmemory: 1GB
minmemory: 512MB
I want to read username, so Dim username = in the settings file: ProGamingHun, how can i do this? The username is unknow leght, because ProGamingHun is a test text. Thanks for helping.
I'm not convinced, the code you posted as answer, parses the file correctly. You're better off, using regular expressions instead:
Dim lines() As String = IO.File.ReadAllLines(SettingsRoot + "\config.cfg")
Dim matches = lines.SelectMany(Function(line) Regex.Matches(line, "(.*): (.*)").Cast(Of Match))
Dim dictionary = matches.ToDictionary(Function(match) match.Groups(1).Value, Function(match) match.Groups(2).Value)
dictionary will now contain the key-value pairs of your settings. Even though this wasn't your original question, you can display them in a message box one by one with the following code:
For Each setting In dictionary
MessageBox.Show(setting.Key & "=" & setting.Value)
Next
Nevertheless, I'd suggest you use one of many standard formats for saving settings. This way, you can use existing libraries to parse them:
XML: ConfigurationManager class
JSON: Json.NET
INI: INI File Parser
EDIT
To get values from the dictionary into individual variables, use dictionary.TryGetValue which handles missing keys (settings):
Dim username As String = Nothing
dictionary.TryGetValue("username", username)