|
I would suggest the first thing you do is try a different URI, because if a different one works, then your problem is with the specific URI you're trying to talk to, and the answer will lie in what they support, not in your code.
Christian Graus
Driven to the arms of OSX by Vista.
"! i don't exactly like or do programming and it only gives me a headache." - spotted in VB forums.
I can do things with my brain that I can't even google. I can flex the front part of my brain instantly anytime I want. It can be exhausting and it even causes me vision problems for some reason. - CaptainSeeSharp
|
|
|
|
|
Hi,
I have a csv file which I can access and read into a dataset with the following code:
Dim conn As New OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & IO.Path.GetDirectoryName(strFilePath) & ";" & _
"Extended Properties=""text;HDR=Yes;FMT=Delimited"";")
Dim FileName As String = IO.Path.GetFileName(strFilePath)
Dim da As New System.Data.OleDb.OleDbDataAdapter("SELECT * FROM " & FileName, conn)
Dim ds As New DataSet
da.Fill(ds, "FileImport")
This works great for the most part but it seems to be converting one of the fields to an integer instead of a decimal. For example: In my csv file I have a PreCost and PostCost column. I've opened up the csv file with notepad and verified that one of the rows contains 1.46 for the PreCost and 1.46 for the postcost. However, using the above code, the dataset after the fill command contains 1.46 for the Precost value and 1 for the postCost value.
I could understand this if the PreCost and PostCost both were converted to 1 but why would only one field get read correctly.
Here's a sample row from the csv file:
01111111 ,01111111111 ,Joe Bloggs ,xxxxxxxx ,18-MAY-2009,11:59:46,01111111111 ,NON GEOGRAPHIC NUMBER ,PEAK ,00:08:34 ,0 ,Y ,N ,1.46 ,1.46 ,
You will notice the 1.46 values for PreCost and PostCost. There is also a blank field after PostCost.
Anyone got any ideas why the dataAdapter.Fill method would do this? and how I get around it?
Updated: I've just tried saving a new csv file with just the row above and headers. The "1.46" values were converted correctly. So why would the original file not process any of the PostCost columns correctly? It appears that everything after the "." is ignored rather than rounded. ie. 1.85 would be converted to 1 and 0.85 would be 0??
|
|
|
|
|
This does seem strange, and I can't tell you for sure why this is happening. There a few thoughts I'd like to think out loud though:
- In you sample csv file does the PostCost field contain values without decimals or a decimal point ? Perhaps the dataAdapter converts the whole column to integer, because the first, last, or majority of rows contain values without a decimal point.
- Is something in the extended properties in the connection string causing this behavior?
- Using Select * leaves the determination of the data types entirely to chance. Using it is only useful if the contents of the files can differ. A work around for this would be to specifically name each column in the query, and if necessary use some sort of cast statement to force the data type.
- If on the other hand, your file does not contain column headers, you probably assign them in the datagrid, or dataview, or somewhere. In the same place you can almost always also determine the data type.
I hope these thoughts help you to find a solution.
Cheers, Johan
My advice is free, and you may get what you paid for.
|
|
|
|
|
Hi,
Thanks for your reply. I think your on to something with this:
"- In you sample csv file does the PostCost field contain values without decimals or a decimal point ? Perhaps the dataAdapter converts the whole column to integer, because the first, last, or majority of rows contain values without a decimal point."
I tried a file with the first record having the postCost value of 0. I still couldn't recreate the error. However, I did manage to replicate the error if I created lots of rows with the initial value of 0 and then the last row having the value 1.46. So I am assuming the first so many rows get scanned to determine a datatype.
So, I need to find a way of specifying the dataType. I'm not sure how I would do this in the Select statement though? I did find this link though which uses a Schema.ini file to force the datatypes. So I will try this:
http://www.aspdotnetcodes.com/Importing_CSV_Database_Schema.ini.aspx[^]
thanks for your help. Much appreciated.
|
|
|
|
|
I am having trouble with the getModuleFileNameEx api call in a VB.net application. It will not return to me the filepath of the currently active window. Any idea what i am doing wrong?
The only output i get currently from lpFileName is ?rmMain (as in the title of the form with a ? in place of the first letter), and that only lasts for one execution of the code. If it is executed more than once per run, it just outputs blank afterwards.
nextWnd = GetForegroundWindow()
' Gets title and path of the active window
GetWindowText(nextWnd, lpString, lpString.Capacity)
modTest = GetModuleFileNameEx(Process.getCurrentProcess, nullWnd, lpFileName, 500)
Thanks,
John
|
|
|
|
|
I'm reading a SQL database created by a PHP app, and there are several columns of data that were Base64 encoded and serialzed. Using VB.NET I'm easily able to take a string of data and decode it, but then have a problem de-serializing the data. I need to do this all in memory, so I use a MemoryStream. But when this is run, it says the stream is not in a binary format.
I'm missing a step or two here???
System.Runtime.Serialization.SerializationException was unhandled
Message="The input stream is not a valid binary format. The starting contents (in bytes) are: 4F-3A-34-3A-22-69-74-65-6D-22-3A-34-3A-7B-73-3A-32 ..."
Source="mscorlib"
Imports System.Runtime.Serialization
Imports System.Runtime.Serialization.Formatters
Imports System.BitConverterImports System.Text.RegularExpressions
Public Class Form1
Private Sub testing()
Dim OrderItem as string
Dim ByteArray() As Byte
Dim DecodedString As String
Dim DeSerializedString as String
OrderItem = "Tzo0OiJpdGVtIjo0OntzOjI6ImlkIjtpOjM0NjA3MztzOjg6InF1YW50aXR5IjtkOjE7czo3OiJvcHRpb25zIjthOjA6e31zOjU6InJlZ2lkIjtzOjA6IiI7fQ=="
ByteArray = System.Convert.FromBase64String(OrderItem)
DecodedString = System.Text.Encoding.ASCII.GetString(ByteArray)
DeserialzedString = Deserialize(DecodedString)
End Sub
Private Function Deserialize(ByVal DecodedString As String) As String
Dim bf As New Binary.BinaryFormatter()
Dim ms As New IO.MemoryStream(System.Text.Encoding.UTF8.GetBytes(DecodedString))
Return bf.Deserialize(ms)
End Function
End Class
|
|
|
|
|
You're not going to get a binary deserialization of a PHP serialized object. If the data was just string data that was serialized using something like an XML Serializer in PHP, then you've got something, but binary, there's no method that I'm familiar with that will get .NET to deserialize a binary object that was no serialized with .NET.
|
|
|
|
|
I've been experimenting with this and cannot get the results I want. I have two multiline textboxes. I want them to resize as the form expands. However, when the form expands, the top textbox will grow over the bottom one. I would like to keep spacing the same. Do I need to write a formula in the form.resize method or what?
Thanks in advance.
|
|
|
|
|
|
On the top multiline textbox, turn off the "bottom" on the anchor setting while.
"There's no such thing as a stupid question, only stupid people." - Mr. Garrison
|
|
|
|
|
Thanks for the answers. I'm still experimenting, but the really helped push me in the right direction.
|
|
|
|
|
want to know how to connect a database to VB.net with codes
|
|
|
|
|
|
http://vb.net-informations.com/[^]
Yours,
KaNNaN
-----------------------------------------------------------------
"Success is When Ur Signature Becomes An Autograph"
Mail To : foreverkans@gmail.com
|
|
|
|
|
How can I set an image file as the user's desktop background image?
Thanks
|
|
|
|
|
|
|
I'm not good at English.
Look at this registry key
HKEY_CURRENT_USER\Control Panel\Desktop
You can find a lot of values in this key. The value named "WallPaper" contains path of the desktop background image. Some of other values describe how should the image be displayed.
Use My.Computer.Registry.SetValue(keyname as String, valueName as String, value as Object) to change the registry.
This is an example code
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
My.Computer.Registry.SetValue("HKEY_CURRENT_USER\Control Panel\Desktop", "WallPaper", "D:\1.jpg")
End Sub
When you click the Button1, it changes your desktop background image path to "D:\1.jpg"
Good luck!
chilinhhacker
|
|
|
|
|
|
Does anybody have any insight on audio streaming through a tv tuner in a vb app? I'm using a directshow2005.dll. I have the video end of it working fine, but the audio does not work. Is there a way to check the graphBuilder or the assigned pins? Or does anybody have any better suggestions? Maybe an updated dll or or completely different one? I was reading some other forums and this seems to truly be a tough topic in everything before 3.5 .net framework.
|
|
|
|
|
Being quite new to VB.NET, I hope someone can guide me through big confusion with BackgroundWorkers.
In my project I have a Main form which holds several backgroundworkers:
1. BGW1 uses a class to collect files into a list of fileinfo (class property)
2. BGW2 processes the files from the list, considering which action to take (copy, convert, etc.)
Meanwhile I think I wouldn't even have to use two separate BGWs for that, but that's not the bigger problem. One of the actions taken in BGW2 retrieves header data from the processed file, which I want to show in a separate form ("frmDump")... and here the trouble begins :
Calling frmDump from the process running in BGW2 shows the form filled with the data, but then it hangs... (the error message is something like the program couldn't communicate with Windows anymore). So I tried using a third backgroundworker BGW3 (member of the main form) and called it from the BGW2 process with the command "mainform.bgw3.RunWorkerAsync()". This way, the form doesn't even fill with data anymore but hangs while opening...
I guess I'm really confused about the issue. Can someone please help me out? I hope I'm at least clear enough that you know what I mean
Thanks
Michael
|
|
|
|
|
Hi,
Threads (all kinds of them, including ThreadPool threads, and BackgroundWorkers) other than the thread that created a Control (BTW: a Form is also a Control), should not access that Control, except for the very few members explicitly allowed, including InvokeRequired and Invoke.
Before .NET 2.0 the app may behave badly, the GUI may freeze, anything can go wrong if you violate the rule.
Since 2.0 you get an InvalidOperationException by default; you can disable that by setting Control.CheckForIllegalCrossThreadCalls false, but that is a very bad idea, and it brings you back in the previous situation.
Since most if not all Controls are somehow related (they are on a Form, one Form owns another Form, etc), the natural consequence is all Controls get created and accessed exclusively by a single thread, typically your initial or main thread, often also called the "GUI thread".
There are lots of examples on InvokeRequired/Invoke available everywhere;
a rather advanced article on the subject is here[^].
Luc Pattyn [Forum Guidelines] [My Articles]
DISCLAIMER: this message may have been modified by others; it may no longer reflect what I intended, and may contain bad advice; use at your own risk and with extreme care.
|
|
|
|
|
Thanks, Luc. I've been reading a lot now and walking through C# examples with my little VB knowledge (BTW I just loved the Asynchronous Method Invocation[^] one).
Still the most important thing in my particular situation is unclear to me: From my main thread (ID10) I start a BackgroundWorker (e.g. it gets ID6) and within this thread I tried to start another BGW which is supposed to open a form (frmDump). From my efforts to trace the IDs I assume it uses the same thread ID (ID6) instead of getting a new one? If so, then this might very well be the reason for the freezing form, right? The first BGW finishes thread ID6, killing the forms instance which I intended to start in a new thread...
Would you be so kind as to give me some example code lines?
Thanks,
Mick
|
|
|
|
|
Hi,
as I said before, all GUI stuff must occur on the main thread, hence NOT on a BackgroundWorker. It just will not work reliably, or not at all, or only for some time. It is WRONG.
Don't bother with thread ID's, you cannot get it right unless you do all GUI stuff on the main thread, no matter what they tell you, it is bound for failure.
FWIW: BackgroundWorkers run on ThreadPool threads, as I have documented here[^].
Luc Pattyn [Forum Guidelines] [My Articles]
DISCLAIMER: this message may have been modified by others; it may no longer reflect what I intended, and may contain bad advice; use at your own risk and with extreme care.
|
|
|
|
|
Thanks again, Luc - but you made it clear already. I might be expressing misunderstandingly, so I have to ask you again, hoping you're in a buddhist kind of mood
The message WHAT I would have to do has become a bit clearer after the articles, but HOW would I do it?
Trying it in other (and hopefully better) words here's my challenge again: I have a certain condition (tested in the first BGW within a 'process filearray' method) which should effect (run by who ever as long it's not me ) in a new form, using the relevant fileinfo object from the BGWs method. This new form has to be independent from the main form (i.e. not blocking it while doing it's own stuff), that's why I tried a separate thread / BGW.
Somehow it doesn't seem very elegant returning a fileinfo object back with 'reportprogress' and then start another thread using that same fileinfo as its parameter... or is that the way to make it work? Do I even need a separate thread for the new (independent) form?
Regards
Mick
|
|
|
|
|