|
Like I said here[^], I'm not really sure that this is a problem with DataSet or that structure. It's really weired.
but from the link that you gave me, it said that a structure should be under 16 KB. maybe. that's the reason.. but what's wrong with dataset?
|
|
|
|
|
Well, I just stuck your complete code snippet in, and when I run it, it gives the correct values: 1 & 3.
I notice there is a try/catch block with no exception handling - perhaps that is hiding the real issue?
But, as the link suggested, try using ByRef for passing the structure.
Public Function SQL1_SearchLotInfo(ByRef a As dataLOTBOX1) As DataSet
This will conserve memory when passing the structure.
|
|
|
|
|
Yes. There is no error in my code. but ~
put the breakpoint on this line " Console.WriteLine(dd.Tables.Count)". then run the application and see the dd.Tables.Count in Quick Watch Window. You will see ""error: cannot obtain value"." ..
Remove the parameter (ByVal a As dataLOTBOX1) from SQL1_SearchLotInfo() function. then, run and check the dd.Tables.Count in Quick Watch Window again. You won't see any error.
|
|
|
|
|
Okay. I see what you mean now.
In my IDE I get the following error message:
"Cannot evaluate expression because we are stopped in a place where garbage collection is impossible, possibly because the code of the current method may be optimized."
This is probably just an issue with the debugger... the code functions properly - just the watch window that goes a bit doo-dah.
HOWEVER,
As mentioned before:
Public Function SQL1_SearchLotInfo(ByRef a As dataLOTBOX1) As DataSet
does NOT have this issue.
Converting the structure to a class (highly recommended) does not have this issue.
|
|
|
|
|
Jasey9 wrote: This is probably just an issue with the debugger... the code functions properly - just the watch window that goes a bit doo-dah
but I tried to get the value in immediate window but not working. I tried to bind the dataset with datagrid but no result is shown. So, I'm not really sure that this is a debugger error or etc.. but you know. if a structure can't handle that much large field, they should doc it.
Jasey9 wrote: Converting the structure to a class (highly recommended) does not have this issue.
Yes. Thanks. I have changed it to a class.
|
|
|
|
|
Michael Sync wrote: The problem is that it's not possible to include more than 59 fields or 60 field in one structure. Due to some many reason, she said that she need to include more 60 fields in that structure. So, I suggested her to use a class with "public shared" instead of structure. but I wanna know why we can't have more than 59 fields or 60 field in one structure?
I wasn't aware of the limitation on a structure. However, it seems a sensible thing. Structures are value types and are copied any time they are assigned or passed into a method and so on. Because of all that copying it makes sense to keep the size of the structure small (I think 16 or 32 bytes is a reasonable maximum).
Classes are reference types and only the reference is copied which means the data isn't copied unless you explicity copy it.
I would recommend that creating a class for this data is a better option than a structure.
|
|
|
|
|
Michael Sync wrote: a class with "public shared"
Also, I don't recommend that the class is Shared (static in C#) because you won't be able to create instances of it.
|
|
|
|
|
Thanks for your reply. Colin.
Colin Angus Mackay wrote: I don't recommend that the class is Shared (static in C#) because you won't be able to create instances of it.
thanks. but there are some codes that she used like structure without creating an instance.
but one thing. Please take a look at "SQL1_SearchLotInfo" in my previous message.
1) There is a parameter in that function.
2) The code that I wrote in that function is just for creating a dataset at runtime. (nothing much)
3) I'm returning that dynamically generated dataset from that function.
(I did nothing with that structure or that parameter.)
My question: Why does that dataset give the error when I use that structure as a parameter? What is the relationship between that structure (parameter) and returned dataset? I tried to return a boolean value and it was working fine. Just having a structure as a parameter in that function makes dataset up-side-down?
|
|
|
|
|
Michael Sync wrote: My question: Why does that dataset give the error when I use that structure as a parameter?
Sorry, I don't see where you are using a as a parameter to the dataset. Could you highlight the correct line of code for me please.
Michael Sync wrote: Just having a structure as a parameter in that function makes dataset up-side-down?
Bottom line is that a structure with over 50 fields in it is not sensible. I don't know the answer to your qestion because I would never have a structure that large in the first place. It is highly inefficient and memory intensive.
|
|
|
|
|
Colin Angus Mackay wrote: Sorry, I don't see where you are using a as a parameter to the dataset. Could you highlight the correct line of code for me please.
Yes. There is no error in my code. but ~
put the breakpoint on this line " Console.WriteLine(dd.Tables.Count)". then run the application and see the dd.Tables.Count in Quick Watch Window. You will see ""error: cannot obtain value"." ..
Remove the parameter (ByVal a As dataLOTBOX1) from SQL1_SearchLotInfo() function. then, run and check the dd.Tables.Count in Quick Watch Window again. You won't see any error.
|
|
|
|
|
So, to summarise: It is NOT a compiler error and your application runs fine. It is just the debugger getting a little confused.
The solution: Don't have such a stupidly large structure in your application. They are not meant to be that large. They are meant to be very small lightweight objects.
|
|
|
|
|
Colin Angus Mackay wrote: It is NOT a compiler error and your application runs fine.
Initially, I was thinking that it might be debugger error. but I tried to bind the result (dataset) with datagrid. but I got no result.
Colin Angus Mackay wrote: The solution: Don't have such a stupidly large structure in your application. They are not meant to be that large. They are meant to be very small lightweight objects.
Yes. thanks. but I hope MS should document about it.
|
|
|
|
|
Michael Sync wrote: I hope MS should document about it.
I'm sure it is documented in several places by Microsoft.
|
|
|
|
|
Colin Angus Mackay wrote: I'm sure it is documented in several places by Microsoft.
documented in several places? yes. that's great. I googled the maximum field limitation of a structure and why it's affected to dataset. but I found none.
|
|
|
|
|
I'm wondering if someone might be able to help me. I've spent a bunch of time on this, read everything I could find, but still can't seem to crack it.
I want to load an assembly .dll into a separate appdomain, from the root directory c:\.
The assembly asm is loaded into the new appdomain fine, BUT ONLY IF ShowForm.dll is in the application default path. I've monkeyed with Applicationbase to request that the load look elsewhere, to no avail. Do I need to specify a security policy?
In any case, is this really the way to load an application into a new appdomain (one which I can subsequently unload)?
Thanks in Advance
Dim Asm = System.Reflection.Assembly.ReflectionOnlyLoadFrom("c:\ShowForm.dll")
Dim ads As New AppDomainSetup()
ads.ApplicationBase = "C:\"
Dim ad As AppDomain = AppDomain.CreateDomain("App2", Nothing, ads)
Dim Asm2 = ad.Load(Asm.fullname)
|
|
|
|
|
Hi Guys,
In a Client/Server application i was writing, i used XML in my own little protocol to send data between the client and the server in a form something like this:
CLIENTID|PROTOCOL_COMMAND_INTEGER|<xml><record><data>I will be you data for today</data></record></xml>|<eof></eof>
Now in the past i've strugled with this xml part because i need encoding that can handle é,è,ç,à and other funny characters like & and stuff..
for this, i could not use datatable.WriteXml(memorystream) (i think) because it always messed up these characters. Being the starting developer that I am , i created a little piece of horrorcode looking like this:
Public Function GetXmlFromRow(ByVal dr As DataRow, ByVal sRecordType As String) As String
Dim sb As New IO.StringWriter
Dim xwXmlTextWriter As New XmlTextWriter(sb)
xwXmlTextWriter.WriteStartDocument()
xwXmlTextWriter.WriteStartElement(sRecordType)
Dim col As DataColumn
For Each col In dr.Table.Columns
xwXmlTextWriter.WriteElementString(col.ColumnName, dr.Item(col).ToString)
Next
xwXmlTextWriter.WriteEndDocument()
xwXmlTextWriter.Flush()
Return sb.ToString
End Function
It isn't pretty.. but it does the job. Now however, i ran into trouble:
i need to send a blob in this XML (a blob which contains another XML file :s). however, i cannot do a ".ToString" from a blob cause it just returns the datatype name as a string.
How can i get a decent formatted XML file from a datatable to send over a socket OR Do i need to rethink my solution completly ? If so: What is the best way/protocol to handle these kinds of things ?
Thanks !
|
|
|
|
|
Hmmm seems you have 2 distinct problems.
1. Unicode in a client dataset - I'm sure it can be done, but I have not had the requirement.
Noctris wrote: How can i get a decent formatted XML file from a datatable
2. Datatabe/set to xlm is simply xmlDataset.writexml(memorystream/variable) I think!
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
You will need to run a REGEX session on your string before you send it to your XMLWriter.
Search GOOGLE for xml unsafe characters and ASCII code to see what you should turn those funny characters into. Since you are making your own server / client application you can set your own REGEX standards for conversion of characters.
IE: REGEX finds a "&" in your input string. You replace "&" with a @045; and send that to your XMLWriter.
|
|
|
|
|
I've Searched for hours and still can't find the answer: How would you load an HTML Page from the resources file into a VS.NET WebBrowser Control using VB?
It's an essential part of my application and I'm quite new to VB. Can anybody Help?
|
|
|
|
|
You can do:
WebBrowser1.DocumentText = My.Resources.HTMLFile
Where HTMLFile is the name of the HTML page you added to the Resources.
Alternatively, you could write out the text of the HTML file and then navigate to it:
My.Computer.FileSystem.WriteAllText("c:\file.html", My.Resources.HTMLFile, False)
WebBrowser1.Navigate("c:\file.html")
I don't know of a way just to load the HTML file in the webbrowser control straight from the resources but that may be due to ignorance on my part.
|
|
|
|
|
Thank you for your response. However I'm still having a little trouble.
Apparently My HTML Page is not a member of My.Resources.
Everything else is appearing in the intellisense panel apart from my web page and style sheet.
Has Anybody got any idea why this might be?
|
|
|
|
|
I had problems with adding a resource once for an HTML file. I ended up booting it to the curb and writing my own HTML structure internal.
Below is a quick HTML entry you can stream towards your WebBrowser object and it will work just fine. It builds a basic web page with a table and has simple Java script support VIA a text box entry. I also disabled any right click to view source function with the entry in the body section oncontextmenu=return false;
Give it a try you may find this easier to deal with.
=========================================================================
Dim tik As String = """"
TextBox.Text = "Add some internal Java Script stuff here if you want for a pop up window or what not"
WebBrowser1.DocumentText = "<%@ Page Language=" & tik & "VB" & tik & "%>" & ControlChars.NewLine & "<html><head><meta http-equiv=" & tik & "content-type" & tik & " content=" & tik & "text/html" & tik & ">" & ControlChars.NewLine & "" & _
"<script language=" & tik & "JavaScript" & tik & ">" & ControlChars.NewLine & "" & _
"<!-- hide" & ControlChars.NewLine & "" & _
"" & TextBox.Text & "" & _
"// -->" & ControlChars.NewLine & "" & _
"</script>" & ControlChars.NewLine & "" & _
"</head>" & ControlChars.NewLine & "<body topmargin=" & tik & "0" & tik & " marginwidth=" & tik & "0" & tik & " marginheight=" & tik & "0" & tik & " bgcolor=" & tik & "#FFFFFF" & tik & " text=" & tik & "#000000" & tik & " link=" & tik & "#000000" & tik & " vlink=" & tik & "#000000" & tik & " alink=" & tik & "#000000" & tik & " oncontextmenu=" & tik & "return false;" & tik & ">" & _
"<font size=" & tik & "2" & tik & " face=" & tik & "Arial, Helvetica, sans-serif" & tik & " color=" & tik & "#000000" & tik & "><table border=" & tik & "0" & tik & " width=" & tik & "610" & tik & " cellpadding=" & tik & "0" & tik & " cellspacing=" & tik & "0" & tik & " bgcolor=" & tik & "#FFFFFF" & tik & ">" & _
"<tr><td><font size=" & tik & "2" & tik & ">•<a href=" & tik & " http://www.codeproject.com" & tik & " target=" & tik & "_blank" & tik & "><b> Code Project Rocks! </b></a><br>" & _
"Where would we be without the help of everyone at Code Project?!?!<br><br></td></tr>" & _
"</table></font></body></html>"
|
|
|
|
|
why not save the file as a .txt file and add it to your resources, then save it as an .html file when you need it? ( or keep it a .txt file the whole time? )
How many bytes of text have I typed in my lifetime??? Man, I wish I kept track...
|
|
|
|
|
Hi all
Noob question
I'm using different web services depending on whether I want to connect to the development back end server or the production one. I'd like to choose which web service to use based on a setting in the web.config file. If I use a case statement (or if etc) to define my object the code complains that the object isn't declared.
e.g.
if Appsettings("Debug") = "True" then
dim myObj as new devServer.Service
else
dim myObj as new prodServer.Service
end if
myVar = myObj.somethingClever
name myobj is not declared
Can this be done in some other way?
Thanks
Dave
|
|
|
|
|
Your issue is that myObj exists within the scope of the if statements. Set myVar to be the right service within the code block, or define myObj outside it, so that it's visible outside of the scope of the if statement.
Christian Graus
Please read this if you don't understand the answer I've given you
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|