Computer Name Write to Sqlite Database

hi,
I have a problemi with insert a data into a field in sqlite database.

In this forum I have found a method that return CString or WString of the ComputerName:

Soft Declare Sub GetComputerNameA Lib “Kernel32” ( name as Ptr, ByRef size as Integer )
Soft Declare Sub GetComputerNameW Lib “Kernel32” ( name as Ptr, ByRef size as Integer )

dim mb as new MemoryBlock( 1024 )
dim size as Integer = mb.Size()

if System.IsFunctionAvailable( “GetComputerNameW”, “Kernel32” ) then
GetComputerNameW( mb, size )
return mb.WString( 0 )
else
GetComputerNameA( mb, size )
return mb.CString( 0 )
end if

I have call this metod “My_Computer_Name” in my program

In the part of the program that writes to database I use:

row.Column(“myrecordfield”) = My_Computer_Name()
DB.InsertRecord(“mytab”, row)

but the problem is that in the field it writes only the first char of the returned string: es: “PC-USER” … it writes “P”

What am I doing wrong ??

Note: the field in the database is defined as TEXT

(This is on Windows, true?) Your problem may be in what you are actually calling for.

Open the OS Control Panel and click on System. In the section on Computer Name, Domain, Workgroup, etc. there is the Computer Name field and a field named Computer Description. Look at the Computer Description field contents. The function “GetComputerNameW” returns that field. The function “GetComputerNameA” returns the Computer Name field.

The way your code is written you are calling “GetComputerNameW” unless that function does not exist in the Kernel.

Excuse me, but I have not explained well.
The problem is that : when I write a WString variable in my field (text field) sqlite database ,it only write the first caracther to that field.

[quote=171429:@Stefano Riva]Excuse me, but I have not explained well.
The problem is that : when I write a WString variable in my field (text field) sqlite database ,it only write the first caracther to that field.[/quote]
Understood. Have you verified in the Debugger that what you are getting from the My_Computer_Name function is the correct data as expected before you write it to the database?

What happens if you were to assign the WString to a String and save the String to the database? WString does an implicit type conversion when assigned to a String type so maybe the problem is with the database not handling WStrings properly.

Escluding the function to get computer name,I have the same result if I write this code:

Dim testwstring As Wstring
Dim teststring As String
testwstring = “hello”

teststring = testwstring

… Databasewrite … (after write my field get this value “h”)

I have resolved with: ConvertEncoding(testwstring , Encodings.WindowsANSI)

return mb.CString( 0 ) —> only return ONE character :wink:

return mb.CString(mb.Size) maybe better or only mb.Cstring()