|
you need to show some code for a better answer
anyway, here's how to serialize xml
class myClass(){}
void SerializeToXML(myClass object)
{
XmlSerializer serializer = new XmlSerializer(typeof(myClass));
TextWriter textWriter = new StreamWriter();
serializer.Serialize(textWriter, object);
textWriter.Close();
}
As you saw in your app, the XMLSerializer also doesn't support circular references. If you need this kind of flexibility, you should consider binary serialization.
Here's how you can serialize to binary
void SerializeToBinary(myClass object, MemoryStream stream)
{
stream.Seek(0, System.IO.SeekOrigin.Begin);
BinaryFormatter formatter = new BinaryFormatter();
formatter.Serialize(stream, object);
}
Use XmlTextWriter to manually create an XML file, and use XmlTextWriter.WriteBase64 to write your binary data into the file. Make sure you add a "length" attribute.
here's how to deserialize the binary back into an object
First make an XmlTextReader, navigate to the Element you wrote and create a MemoryStream
then create a byte[array] and put the data in it
xr.MoveToAttribute("length");
xr.ReadAttributeValue();
int length = Int32.Parse(xr.Value);
byte[] data = new byte[length];
xr.ReadBase64(data, 0, length);
stream.Write(data, 0, length);
now you can deserialize your object
stream.Seek(0, System.IO.SeekOrigin.Begin);
IFormatter formatter = new BinaryFormatter();
myClass object = (myClass)formatter.Deserialize(stream);
|
|
|
|
|
See the end of this message for details on invoking
just-in-time (JIT) debugging instead of this dialog box.
************** Exception Text **************
System.Data.OleDb.OleDbException: Could not find file 'D:\Documents and Settings\Raj Computer\Local Settings\Apps\2.0\8JC0578H.AN4\N27XQ98C.YR9\abcd..tion_6cdeed2b4dc164ad_0001.0000_dd2b28ab3a97d826\Database2.mdb'.
at System.Data.OleDb.OleDbConnectionInternal..ctor(OleDbConnectionString constr, OleDbConnection connection)
at System.Data.OleDb.OleDbConnectionFactory.CreateConnection(DbConnectionOptions options, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningObject)
at System.Data.ProviderBase.DbConnectionFactory.CreateNonPooledConnection(DbConnection owningConnection, DbConnectionPoolGroup poolGroup)
at System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection owningConnection)
at System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory)
at System.Data.OleDb.OleDbConnection.Open()
at WindowsApplication1.Form1.Form1_Load(Object sender, EventArgs e)
at System.EventHandler.Invoke(Object sender, EventArgs e)
at System.Windows.Forms.Form.OnLoad(EventArgs e)
at System.Windows.Forms.Form.OnCreateControl()
at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
at System.Windows.Forms.Control.CreateControl()
at System.Windows.Forms.Control.WmShowWindow(Message& m)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ScrollableControl.WndProc(Message& m)
at System.Windows.Forms.ContainerControl.WndProc(Message& m)
at System.Windows.Forms.Form.WmShowWindow(Message& m)
at System.Windows.Forms.Form.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
************** Loaded Assemblies **************
mscorlib
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.3053 (netfxsp.050727-3000)
CodeBase: file:///D:/WINDOWS/Microsoft.NET/Framework/v2.0.50727/mscorlib.dll
----------------------------------------
abcd
Assembly Version: 1.0.0.0
Win32 Version: 1.0.0.0
CodeBase: file:///D:/Documents%20and%20Settings/Raj%20Computer/Local%20Settings/Apps/2.0/8JC0578H.AN4/N27XQ98C.YR9/abcd..tion_6cdeed2b4dc164ad_0001.0000_dd2b28ab3a97d826/abcd.exe
----------------------------------------
Microsoft.VisualBasic
Assembly Version: 8.0.0.0
Win32 Version: 8.0.50727.3053 (netfxsp.050727-3000)
CodeBase: file:///D:/WINDOWS/assembly/GAC_MSIL/Microsoft.VisualBasic/8.0.0.0__b03f5f7f11d50a3a/Microsoft.VisualBasic.dll
----------------------------------------
System
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.3053 (netfxsp.050727-3000)
CodeBase: file:///D:/WINDOWS/assembly/GAC_MSIL/System/2.0.0.0__b77a5c561934e089/System.dll
----------------------------------------
System.Windows.Forms
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.3053 (netfxsp.050727-3000)
CodeBase: file:///D:/WINDOWS/assembly/GAC_MSIL/System.Windows.Forms/2.0.0.0__b77a5c561934e089/System.Windows.Forms.dll
----------------------------------------
System.Drawing
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.3053 (netfxsp.050727-3000)
CodeBase: file:///D:/WINDOWS/assembly/GAC_MSIL/System.Drawing/2.0.0.0__b03f5f7f11d50a3a/System.Drawing.dll
----------------------------------------
System.Configuration
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.3053 (netfxsp.050727-3000)
CodeBase: file:///D:/WINDOWS/assembly/GAC_MSIL/System.Configuration/2.0.0.0__b03f5f7f11d50a3a/System.Configuration.dll
----------------------------------------
System.Xml
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.3053 (netfxsp.050727-3000)
CodeBase: file:///D:/WINDOWS/assembly/GAC_MSIL/System.Xml/2.0.0.0__b77a5c561934e089/System.Xml.dll
----------------------------------------
System.Runtime.Remoting
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.3053 (netfxsp.050727-3000)
CodeBase: file:///D:/WINDOWS/assembly/GAC_MSIL/System.Runtime.Remoting/2.0.0.0__b77a5c561934e089/System.Runtime.Remoting.dll
----------------------------------------
System.Data
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.3053 (netfxsp.050727-3000)
CodeBase: file:///D:/WINDOWS/assembly/GAC_32/System.Data/2.0.0.0__b77a5c561934e089/System.Data.dll
----------------------------------------
System.Transactions
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.3053 (netfxsp.050727-3000)
CodeBase: file:///D:/WINDOWS/assembly/GAC_32/System.Transactions/2.0.0.0__b77a5c561934e089/System.Transactions.dll
----------------------------------------
************** JIT Debugging **************
To enable just-in-time (JIT) debugging, the .config file for this
application or computer (machine.config) must have the
jitDebugging value set in the system.windows.forms section.
The application must also be compiled with debugging
enabled.
For example:
<configuration>
<system.windows.forms jitdebugging="true">
When JIT debugging is enabled, any unhandled exception
will be sent to the JIT debugger registered on the computer
rather than be handled by this dialog box.
|
|
|
|
|
Basically, it's telling you it can't find your database file, Database2.mdb.
Apparently you're using ClickOnce deployment and your connection string is eithwe wrong or your database file didn't get deployed with your app for some reason.
Read these[^] for some tips on resolving the issue.
|
|
|
|
|
wat is the procedure for it can u tell me about this
|
|
|
|
|
jitendra rajbher wrote: wat is the procedure for it can u tell me about this
Did you at least care to click the link that Dave posted?
|
|
|
|
|
ya, i have seen and used in click once but by using that my data is not been showing in the data base,all the procedure is working but i am not able to see the data where it is been store
|
|
|
|
|
I already told you to start reading the links I posted. I can't tell you the procedure to fix your problem because there are many different causes of it and YOU have to do the research into which one you're facing.
|
|
|
|
|
I'm programming with VB .NET 2010 and using a Microsoft Access Database file which is bound to my project as a Dataset. Now I want to know: BEFORE inserting a new row into my dataset table what will be the new ID number, or totally is it possible to know?
Surely you know the autonumber ID of a table is different with row count number, for there may be deleted rows between the table rows. Like the following example:
Row 0: ID=1
Row 1: ID=2
Row 2: ID=4 (ID number 3 is deleted)
Row 3: ID=5
Row 4: ID=9 (ID numbers 6,7,8 are deleted)
Now how do we know what ID number of Row 5 will be before inserting the new row? Perhaps ID numbers 10 and 11 are either deleted or not, so it may be 10, may be 11 or 12 or whatever! Is there a way to know it BEFORE adding or inserting the new row into the table?
Thank you beforehand.
|
|
|
|
|
There is no way to know beforehand if you are using a standard identity value. If you need to know this beforehand, you are either going to have to generate the value yourself, or use something like a GUID instead - which you can assign in your code.
|
|
|
|
|
|
One way is to store the last ID number in another table and increment it whenever a row is inserted into the table.
|
|
|
|
|
Yes that's the best way, thanks for your remark.
|
|
|
|
|
Hi Experts,
I am new with VS2008 and not able to find Event icon in Property window or anybody can tell me how i can view all events of particular control.
FYI..I am working with WPF.
Thanks,
Kidya
modified on Tuesday, August 30, 2011 3:31 AM
|
|
|
|
|
At the top of the properties window you should see a tab with a yellow lightning bolt. Click on that and it should display all the available events for the highlighted control
"You get that on the big jobs."
|
|
|
|
|
i am a beginner want to learn OOP in VB.Net.
In theory i understand OOP, but i do not understand apply in form of coding.
i need a sample application OOP, suppose the application inventory.Because i want to see how the use of OOP.
so, please help and teach me.
Thank you very much if you wanna help me..
|
|
|
|
|
|
thank you very much.. i try first..
|
|
|
|
|
How are you making out with this? Any specific questions?
|
|
|
|
|
visualst wrote: so, please help and teach me.
I think you should pick up a book on OOPS with .Net and read it.
Too much of heaven can bring you underground
Heaven can always turn around
Too much of heaven, our life is all hell bound
Heaven, the kill that makes no sound
|
|
|
|
|
hmm, i have a book. but i confuse in build a class like connection to databases.
but thank you for your advice.
|
|
|
|
|
|
how to get and display values in listbox in vb.net
|
|
|
|
|
One way to add values is to a add item by item.
E.g. listbox.Add("A");
You can add a range
E.g.
Dim s1 As String = "A"
Dim s2 As String = "B"
Dim s3 As String = "C"
listbox.Items.AddRange(New String() {s1, s2, s3})
A third way is to bind a collection to the listbox.
For this, you will use the DataSource and the DisplayMember property.
E.g.
listbox.DataSource = ds
listbox.DisplayMember = "ColumnName"
Too much of heaven can bring you underground
Heaven can always turn around
Too much of heaven, our life is all hell bound
Heaven, the kill that makes no sound
|
|
|
|
|
Further to the previous post, you can also iterate the listbox items collection like;
For Each item As String in listbox1.Items
Debug.Writeline(item)
Next
|
|
|
|
|
To expand on Dave's answer, remember that the items don't have to be strings (DataRows, for instance):
For Each item As String in listbox1.Items
Debug.Writeline(item)
Next
Could be
For Each item As DataRow in listbox1.Items
Next
Also, if you're looking for just the items that have been selected, replace
listbox1.Items with
listbox1.SelectedItems
|
|
|
|