I have a database that contains the data as in the following picture
Notes:
Collation Database ('SQL_Latin1.General_CP1_CI_AS').
I have no right to change Collation to Araic_CI_AS.
In case you change Collation to Araic_CI_AS, the data display from the database is displayed in the new program, but the program has a problem and it appears in the old program in the form of ????? Where the old program.
I can not modify the old program because there is no source code for it.
This database is outdated and may not be modified by anyone ( Collation [rows] or Collation [databases])
When you link the database to a new standalone program through Visual Basic 2015 to use some data from the database, the following format appears as in the picture...
What I want is to display the content of the database to change the (ãßÇÆä æÂáÇÊ) sentence to the default language which is Arabic.
I hope to find a solution through the Visual Basic code and not through the amendment to the database.
Thanks to all
The problem has been solved in the process of converting the encoding characters by the following code:
Private Function conv1256(ByVal txt As String) As String
Dim dic As New Dictionary(Of String, String)
Const _1256 As String = "ÐÏÌÍÎåÚÛÝÞËÕÖØßãäÊÇáÈíÓÔÙÒæÉìÑÄÁÆøºÅñõðó¡ÜÃòö¿Âú"
Const _utf8 As String = "ذدجحخهعغفقثصضطكمنتالبيسشظزوةىرؤءئّ؛إًٌَُ،ـأٍِ؟آْ"
For i = 0 To (_1256.Length) - 1
dic.Add(_1256.Chars(i), _utf8.Chars(i))
Next i
For Each ch In txt
conv1256 &= If(dic.ContainsKey(ch), dic.Item(ch), ch)
Next
End Function
To be used this way:
MsgBox(conv1256("ÈÓãö Çááå ÇáÑøÍãä ÇáÑøÍíã"))
Good luck and thank you all
Related
I am developing a VB.NET update system for a volunteer organisation’s MS Access database. The database is protected by a password as it contains personal information. I have created the application using the VB designer. I need to be able to code the application so that, if the owner decides to change the MS Access password, they will have no need to come back to me to change the code and rebuild the solution. In other words, I do not want the password to be hard coded in the app.config file or the settings.designer.vb file. My code should not need to know the password as a simple call to one of the Fill functions can test any password entered by the user. My problem is that I have found no way to alter the connection string that is tested in the setttings.designer.vb code whenever the database is accessed. I am using Visual Studio 2017.
I have spent a long time searching the web for answers and have tried various solutions involving the configurationmanager without success. I am new to this area so I would be most grateful if anyone here can help.
Here is my latest attempt which still produces an invalid password error even though the third debug statement suggests that the connection string, including the password, has been correctly set.
Public Sub UpdateConnString(connString As String)
Dim configFileMap As New ExeConfigurationFileMap()
Dim config As Configuration = ConfigurationManager.OpenExeConfiguration(configFileMap.ExeConfigFilename)
Dim connStringName As String = "TestConnectionString"
Debug.Print("0 " + config.ConnectionStrings.ConnectionStrings(connStringName).ConnectionString)
config.ConnectionStrings.ConnectionStrings(connStringName).ConnectionString = connString
Debug.Print("1 " + config.ConnectionStrings.ConnectionStrings(connStringName).ConnectionString)
config.Save(ConfigurationSaveMode.Modified, True)
Debug.Print("2 " + config.ConnectionStrings.ConnectionStrings(connStringName).ConnectionString)
End Sub
Just because a connection string is stored in the config file, you aren't required to use it as it is. You can read in that default value and then edit it before using it, e.g.
Dim builder As New OleDbConnectionStringBuilder(My.Settings.DefaultConnectionString)
builder.DataSource = dataSource
Dim connectionString = builder.ConnectionString
You can add or modify any part of a connection string you want that way at run time.
Thank you for your response. Unfortunately, the code throws a compilation error - "DefaultConnectionString is not a member of My.Settings".
Fortunatley I have now managed to find a working solution:
'My.Settings.Item("TestConnectionString") = connectionString
I upgraded to Visual Studio 2015 from 2012, and it royally screwed me over. I can no longer import WAV files into my project's resources without it turning them into a MemoryStream, which my code won't accept. I have been searching for hours now, and I am getting really frustrated. Will someone please help me with this? I am importing the files exactly according to these instrutions: How to: Import or Export Resources
Let me know if you need pictures or other info. I am getting really desperate at this point.
I don't know exactly what experience you think you had in VS 2012 but I just tested VS 2015, 2013 and 2012 and they all worked exactly the same way. I simply opened the project properties, selected the Resources page, clicked the Add Resource drop-down, selected Add Existing File and navigated to the WAV file I wanted. The file was added as a resource and the corresponding property of My.Settings exposed that resource as type UnmanagedMemoryStream. As I said, that happened exactly the same way in all three versions. If you got something different in VS 2012 then you did something different in VS 2012. You haven't told us what you did so we can only guess.
Exactly what type of data does your code expect? Maybe that would have been good information to provide too. If it's a Byte array then you can get one from that resource Stream like so:
Dim resourceStream = My.Resources.MyWavResource
Dim length = CInt(resourceStream.Length)
Dim resourceData(length - 1) As Byte
resourceStream.Read(resourceData, 0, length)
That's exactly how you read from any Stream to a Byte array. You could, if you needed to do this more than once, put that into a method:
Private Function GetStreamData(stream As Stream) As Byte()
Dim length = CInt(stream.Length)
Dim data(length - 1) As Byte
stream.Read(data, 0, length)
Return data
End Function
You could call it like this:
Dim data As Byte()
Using resource = My.Resources.MyWavResource
data = GetStreamData(resource)
End Using
You could even write it as an extension method and then call it on the Stream itself.
The link you are using is VS 2010.
Open your Resource file. By default the Top Left menu is Strings; but there is a small drop down arrow. Click this and the fourth option is Audio. If you now click add existing file, by default it will filter for .wav files, and will add them as such.
I need help with how to work on text file (like database).
I create excel GUI (with macro's), that search imputed string in sheets with lots of data and display entire row with matching string (for people with installed MS office)
Now I must create alternative VB.Net application working only on tab delimited text files (without ADO.Net) for people who haven't installed MS office, and I don't know how start to work with it.
import them? if yes, then how.
working directly on them? if yes, then how.
My text files is exported excels files/sheets to tab delimited .txt, with loots of columns (100+) with headers, and lots of rows 500+
need help :)
thx
If you want to get the headers from the first line of the file then do this ...
Sub Main()
Dim dt = New DataTable
Dim lines = File.ReadAllLines("TextFile1.txt")
Dim headers = lines(0).Split(vbTab)
For Each header In headers
dt.Columns.Add(header)
Next
For Each line In lines.Skip(1)
Dim parts = line.Split(vbTab)
dt.Rows.Add(parts)
Next
End Sub
I have this txt file with the following information:
National_Insurence_Number;Name;Surname;Hours_Worked;Price_Per_Hour so:
eg.: aa-12-34-56-a;Peter;Smith;36;12
This data has been inputed to the txt file through a VB form which works totally fine, the problem comes when, on another form. This is what I expect it to do:
The user will input into a text box the employees NI Number.
The program will then search through the file that NI Number and, if found;
It will fill in the appropriate text boxes with its data.
(Then the program calculates tax and national insurance which i got working fine)
So basically the problem comes telling the program to search that NI number and introduce each ";" delimited field into its corresponding text box.
Thanks for all.
You just need to parse the file like a csv, you can use Microsoft.VisualBasic.FileIO.TextFieldParser to do this or you can use CSVHelper - https://github.com/JoshClose/CsvHelper
I've used csv helper in the past and it works great, it allows you to create a class with the structure of the records in your data file then imports the data into a list of these for searching.
You can look here for more info on TextFieldParser if you want to go that way -
Parse Delimited CSV in .NET
Dim afile As FileIO.TextFieldParser = New FileIO.TextFieldParser(FileName)
Dim CurrentRecord As String() ' this array will hold each line of data
afile.TextFieldType = FileIO.FieldType.Delimited
afile.Delimiters = New String() {";"}
afile.HasFieldsEnclosedInQuotes = True
' parse the actual file
Do While Not afile.EndOfData
Try
CurrentRecord = afile.ReadFields
Catch ex As FileIO.MalformedLineException
Stop
End Try
Loop
I'd recommend using CsvHelper though, the documentation is pretty good and working with objects is much easier opposed to the raw string data.
Once you have found the record you can then manually set the text of each text box on your form or use a bindingsource.
WP8, VS12, & C#
I've started creating an app which allows me to store relational data in a local database using LINQ to SQL.
What I'd like to do next is be able to update the existing data...I would click an icon in the appbar and be taken to the previously saved data so I could update it.
I've looked on msdn... Local database for Windows Phone, and I would like to know if the following code I see at section Using the database > Updating data is valid given my LINQ to SQL set-up. If so, how do I go about adding this code to allow updating?
protected override void OnNavigatedFrom(System.Windows.Navigation.NavigationEventArgs e)
{
//Call base method
base.OnNavigatedFrom(e);
//Save changes to the database
toDoDB.SubmitChanges();
}
If anyone could point to a working example or help me hook up the ability to update data, I would be grateful.
Much Thanks,
k
Yhello, dunno if you still working on your project but I've got a solution for you.
From your site (msdn), here what I found :
First, query the database for the object that is to be updated. Then, modify the object as desired. Finally, call the SubmitChanges method to save the changes to the local database.
So, you need to query your db (example from my own VB.net code)
Dim monContact = From contact As Authentification In bddGLI.TableAuth Select contact
Execute the query and get the result in a collection
Dim resultCollection = New ObservableCollection(Of Authentification)(monContact)
Run through this collection with a ForEach loop and modify your object
For Each elem As Authentification In resultCollection
elem.Mail = txtEmail.Text
elem.Nom = txtNom.Text
elem.Prenom = txtPrenom.Text
Next
And don't forget to save your db
bddGLI.SubmitChanges()
Now, how to check if you really updated your data ?
Where I create my db, i inserted some data test in my table
Using db As New GeoLiveInfoDataContext(GeoLiveInfoDataContext.DBConnectionString)
If db.DatabaseExists() = False Then
db.CreateDatabase()
Dim contact As New Authentification
With contact
.Nom = ""
.Prenom = ""
.Mail = ""
End With
db.TableAuth.InsertOnSubmit(contact)
db.SubmitChanges()
End If
End Using
http://msdn.microsoft.com/en-us/library/windowsphone/develop/hh286408(v=vs.105).aspx
Go to C:\Program Files (x86)\Microsoft SDKs\Windows Phone\v8.0\Tools\IsolatedStorageExplorerTool
SHIFT + right clic => open prompt here
ISETool.exe ts xd {ID APP HERE FROM MANIFEST } {PATH}
Don't forget to install your app on the emulator or device (not debugging)
Now at your path, you have a .sdf which can be open with SQL server Compact Edition.
Do this command before and after updating and check the difference.
Use Sqlight -- Here is a great example http://code.msdn.microsoft.com/wpapps/Using-Sqlite-with-WP8-52c3c671
The important thing in updating the data in the database is, that you handle with the same object which results the query from database and don't copy it. You can pass the object from the query results to other objects or functions but make sure that it is still the same object on the heap. Just in this case the SubmitChanges works. I did it the first time wrong and copied it for the page object and then passed it back and the SubmitChanges didn't work.