|
One of my friends is doing one VB.NET project. but she said that she always get this error "error: cannot obtain value".
The code is like that.
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim f As New Foo
Dim dd As DataSet = f.SQL1_SearchLotInfo(Nothing)
Console.WriteLine(dd.Tables.Count)
Console.WriteLine(dd.Tables(0).Rows.Count)
End Sub
End Class
Public Class Foo
Public Function SQL1_SearchLotInfo(ByVal a As dataLOTBOX1) As DataSet
Dim Table1 As DataTable
Table1 = New DataTable("Customers")
'creating a table named Customers
Dim Row1, Row2, Row3 As DataRow
'declaring three rows for the table
Try
Dim Name As DataColumn = New DataColumn("Name")
'declaring a column named Name
Name.DataType = System.Type.GetType("System.String")
'setting the datatype for the column
Table1.Columns.Add(Name)
'adding the column to table
Dim Product As DataColumn = New DataColumn("Product")
Product.DataType = System.Type.GetType("System.String")
Table1.Columns.Add(Product)
Dim Location As DataColumn = New DataColumn("Location")
Location.DataType = System.Type.GetType("System.String")
Table1.Columns.Add(Location)
Row1 = Table1.NewRow()
'declaring a new row
Row1.Item("Name") = "Reddy"
'filling the row with values. Item property is used to set the field value.
Row1.Item("Product") = "Notebook"
'filling the row with values. adding a product
Row1.Item("Location") = "Sydney"
'filling the row with values. adding a location
Table1.Rows.Add(Row1)
'adding the completed row to the table
Row2 = Table1.NewRow()
Row2.Item("Name") = "Bella"
Row2.Item("Product") = "Desktop"
Row2.Item("Location") = "Adelaide"
Table1.Rows.Add(Row2)
Row3 = Table1.NewRow()
Row3.Item("Name") = "Adam"
Row3.Item("Product") = "PDA"
Row3.Item("Location") = "Brisbane"
Table1.Rows.Add(Row3)
Catch
End Try
Dim ds As New DataSet()
ds = New DataSet()
'creating a dataset
ds.Tables.Add(Table1)
Return ds
End Function
End Class
Public Structure dataLOTBOX1
Dim TDATE As Date
Dim BOX As String
Dim UTACLOTID As String
Dim RLOTID As String
Dim CUSTLOTID As String
Dim PARTID As String
Dim SUPPLIERID As String
Dim INPART As String
Dim OUTPART As String
Dim DATECODE As String
Dim STAGE As String
Dim CUSTDEVICE As String
Dim CUSTOMERPACKAGE As String
Dim PACKAGESIZE As String
Dim PINCOUNT As Integer
Dim TOTALQTY As Integer
Dim TB1 As Integer
Dim TB2 As Integer
Dim TB3 As Integer
Dim TB4 As Integer
Dim TB5 As Integer
Dim TB6 As Integer
Dim TB7 As Integer
Dim TB8 As Integer
Dim TB9 As Integer
Dim TB10 As Integer
Dim TB11 As Integer
Dim TB12 As Integer
Dim TB13 As Integer
Dim TB14 As Integer
Dim TB15 As Integer
Dim TB16 As Integer
Dim TB17 As Integer
Dim TB18 As Integer
Dim TB19 As Integer
Dim TB20 As Integer
Dim AB As Integer
Dim EB1 As Integer
Dim EB2 As Integer
Dim EB3 As Integer
Dim EB4 As Integer
Dim EB5 As Integer
Dim EB6 As Integer
Dim FB As Integer
Dim DEFAULTFLOW_LOTBOX As String
Dim NEWBOX As String
Dim FINALFLOW As String
Dim ITEM As String
Dim STATUS As String
Dim OLDSTATUS As String
Dim REMARK As String
Dim TRANID As String
Dim INAME As String
Dim IEMPLOYEE As String
Dim IDATE As Date
Dim CNAME As String
Dim CEMPLOYEE As String
Dim CDATEE As Date
Dim ANAME As String
Dim ADATE As Date
Dim WOFFICER As String
End Class
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?
thanks in advance.
|
|
|
|
|
From what I understand, structures are value types, and as such are created on the stack. This would mean there is a limit to their size, but 59-60 fields seems rather small!
Classes are reference types, so dont have this same limitation - I think they are stored on the heap.
Of course, I may be totally wrong - please correct me if I am.
Reading here http://www.pcreview.co.uk/forums/thread-1397441.php[^] has someone with a similar issue... and it seems to back up what I initially thought.
I'm glad you asked that question... I am going to be much more wary of structures now
|
|
|
|
|
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...
|
|
|
|