|
 I think the best way to do this is to create a new class for holding whole of your data. about the GPD you used in the code ,as a tip holding serialized streams is not a good choice ,I think you can serialize whole of your GPDs together (because they are marked as serializable)
and in the code you put all your data in one stream ,retrieving from it is not impossible but is far more harder than use a new class to hold all of your data
here is the scheme of such a class (it has some works to be a complete one)
<code>
[XmlRoot("MyData")]
[Serializable]
class MyData
{
ArrayList shapeTypeList;
ArrayList colorList;
ArrayList coordList;
ArrayList sizeList;
ArrayList graphicsPathDataList;
[XmlArray("ShapeData")]
[XmlArrayItem("Shape",typeof())]
public ArrayList ShapeTypeList
{
get { return this.shapeTypeList; }
}
[XmlArray("ColorData")]
[XmlArrayItem("Color",typeof())]
public ArrayList ColorList
{
get { return this.colorList; }
}
[XmlArray("CoorinationData")]
[XmlArrayItem("Coordination",typeof())]
public ArrayList CoordList
{
get { return this.coordList; }
}
[XmlArray("SizeData")]
[XmlArrayItem("Size",typeof())]
public ArrayList SizeList
{
get { return this.sizeList; }
}
[XmlArray("GPDData")]
[XmlArrayItem("GPD",typeof())]
public ArrayList GraphicsPathDataList
{
get { return this.graphicsPathDataList; }
}
public MyData(ArrayList shape, ArrayList color, ArrayList coord, ArrayList size, ArrayList gpd)
{
this.shapeTypeList = shape;
this.colorList = color;
this.coordList = coord;
this.sizeList = size;
this.graphicsPathDataList = gpd;
}
static MyData BinLoad(string path)
{
BinaryFormatter binSer=new BinaryFormatter();
FileStream fo=new FileStream(path,FileMode.Open);
object data=binSer.Deserialize(fo);
fo.Close();
return data as MyData;
}
void BinSerialize(string path)
{
BinaryFormatter binSer=new BinaryFormatter();
FileStream fo=new FileStream(path,FileMode.OpenOrCreate);
binSer.Serialize(fo,this);
fo.Close();
}
static MyData XmlLoad(string path)
{
XmlSerializer xmlSer=new XmlSerializer(typeof(MyData));
FileStream fo=new FileStream(path,FileMode.Open);
object data=xmlSer.Deserialize(fo);
fo.Close();
return data as MyData;
}
void XmlSerialize(string path)
{
XmlSerializer xmlSer=new XmlSerializer(this.GetType());
FileStream fo=new FileStream(path,FileMode.OpenOrCreate);
xmlSer.Serialize(fo,this);
fo.Close();
}
public enum SerializeTo{XML,Binary};
public void Serialize(string path,SerializeTo to)
{
if(to==SerializeTo.Binary)
this.BinSerialize(path);
else
this.XmlSerialize(path);
}
public static MyData Load(string path,SerializeTo to)
{
if(to==SerializeTo.Binary)
return BinLoad(path);
else
return XmlLoad(path);
}
}
</code>
I'm not sure it works just after putting the types because I couldn't test that, but i'm sure it will give you the clue
another thing MyData Class can be serialize in both Xml and Binary
hope the post would be useful
good luck my friend
|
|
|
|
|
hi,
After i serialize a few arraylist, my xml file seem to look like below:
<code>
<?xml version="1.0" encoding="utf-8"?>
<ArrayOfAnyType xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<anyType xsi:type="xsd:int">1</anyType>
</ArrayOfAnyType><?xml version="1.0" encoding="utf-8"?>
<ArrayOfAnyType xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<anyType xsi:type="Color" />
</ArrayOfAnyType><?xml version="1.0" encoding="utf-8"?>
<ArrayOfAnyType xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<anyType xsi:type="ArrayOfPoint">
<Point>
<X>40</X>
<Y>18</Y>
</Point>
<Point>
<X>110</X>
<Y>18</Y>
</Point>
<Point>
<X>110</X>
<Y>68</Y>
</Point>
<Point>
<X>40</X>
<Y>68</Y>
</Point>
</anyType>
</ArrayOfAnyType><?xml version="1.0" encoding="utf-8"?>
<ArrayOfAnyType xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" /><?xml version="1.0" encoding="utf-8"?>
<ArrayOfAnyType xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<anyType xsi:type="MemoryStream">
<Position>142</Position>
<Capacity>256</Capacity>
</anyType>
</ArrayOfAnyType></code>
is this an error? why does is the elements is named '<ArrayOfAnyType>'
Besides, how do i deserialize arraylist of different types.
first i declareas shown below:(this is declare in Form, i did not use MyData class, instead all arraylist is declared in the form)
<code>XmlSerializer s = new XmlSerializer( typeof(ArrayList),new Type[] {typeof(Coordinate),typeof(ColorL),typeof(SizeL), typeof(ArrSave)} );
</code>
then in Load function:
<code>
filename = openFileDialog.FileName;
Stream myStream = openFileDialog.OpenFile();
ShapeTypeList = (ArrayList) s.Deserialize(myStream);
ColorList = (ArrayList) s.Deserialize(myStream);
CoordList = (ArrayList)s.Deserialize(myStream);
SizeList = (ArrayList) s.Deserialize(myStream);
arr=(ArrayList) s.Deserialize(myStream);
arr=(ArrayList) s.Deserialize(myStream);
for(int i=0;i<arr.Count;i++)
{
Stream newStream = new MemoryStream(((MemoryStream)arr[i]).ToArray());
GraphicsPath gpDeserialized = GraphicsPathData.GetGraphicsPath(newStream);
PathList.Add(gpDeserialized);
}
myStream.Close();
r.Close();
</code>
thanks for any reply. Sorry if if my method is wrong. Just trying a different way.
|
|
|
|
|
While i am executing the following code, i am getting the error 'Input string was not in a correct format'
for(i=0;i<=6;i=i+2)
{
for(j=0;j<=485;j++)
{
ran = (Excel.Range)Worksheet.Cells[j+1, i+1];
s[i,j]= int.Parse((string)ran.Text);
tw.WriteLine("The Value of M["+i+"]["+j+"] is" + s[i,j]);
}
}
i am storing total 400 values from the excel sheet, i am having problem at A287
this is the output file
The Value of M[0][284] is-5
The Value of M[0][285] is-3
The Value of M[0][286] is-4
The Value of M[0][
here i am getting exception
|
|
|
|
|
It means that A287 contains something that isn't string representation of number. Instead of int.Parse use int.TryParse to see if the string can be parsed as number.
|
|
|
|
|
an empty string would not be acceptable.
Luc Pattyn [Forum Guidelines] [My Articles]
this weeks tips:
- make Visual display line numbers: Tools/Options/TextEditor/...
- show exceptions with ToString() to see all information
- before you ask a question here, search CodeProject, then Google
|
|
|
|
|
I have two forms:
the first contains a dataGridView containing a list of staff members.
it also contains 4 buttons.
1. refesh
2. update
3. add
4. delete
The add_click event opens a second form for inserting the staff member's details.
when you click the OK button on this form it must update the Staff DB
the code in this event is as follows:
public void OKbutton_Click(object sender, EventArgs e)
{
SqlCommand insertCommand = new SqlCommand("insert into Staff (Lastname,Firstname,TelephoneExtension) values (lastname,firstname,telephoneExtension)");
insertCommand.Parameters.Add("lastname", SqlDbType.NVarChar, 80, "Lastname");
insertCommand.Parameters.Add("firstname", SqlDbType.NVarChar, 80, "Firstname");
insertCommand.Parameters.Add("telephoneExtension", SqlDbType.NVarChar, 0, "TelephoneExtension");
//mySqlDataAdapter2.InsertCommand = insertCommand;
//mySqlDataAdapter2.Update(myDataSetAddandUpdateForm, "Staff");
this.Close();
}
My code is not working. can anyone help me please. I am a trainee programmer.
|
|
|
|
|
Can you be more specific? Is there any exception thrown during execution or just database doesn't get updated?
|
|
|
|
|
I think ur making a lot of mistakes in this... I'd recommend that you go thru a few walkthoughs on MSDN and next time plz take the time to tell us about ur platform. like C# 1.1,2.0 ... SQL Server 2000 uknow!
by the way you're not ExecutenonQuery here and are the syntax of the insert command is all wrong aswell u give parametes in SQL starting with the @ sign. In summary your all messed up here. First study the basics thorougly then start coding ok, dont worry u'll get over it in quick time. Remember... Every body falls the first time!
Rocky
You can't climb up a ladder with your hands in your pockets.
|
|
|
|
|
Thank you...
I use Visual Studio 2005 with SQL Server Express.
I need to hard code everything and not make use of the data adapter configuration wizard.
I need to do this small project so I can learn how this all works, but was just told: go figure it out yourself...
Can you suggest a walkthrough on MSDN I can follow please. im desperate.
thank you
from a sunny south africa.
|
|
|
|
|
just copy paste this URL in your MSDN 2005 URL bar
ms-help://MS.MSDNQTR.v80.en/MS.MSDN.v80/MS.VisualStudio.v80.en/dv_raddata/html/15a88fb8-3bee-4962-914d-7a1f8bd40ec4.htm
There's whole list of walkthroughs
This one's from that list showing you how to save data
ms-help://MS.MSDNQTR.v80.en/MS.MSDN.v80/MS.VisualStudio.v80.en/dv_raddata/html/68befa96-7463-43e8-abcf-dc2f42ccd53d.htm
hope thats helpful for and dont get so desperate, its all abt using ur mind, MSDN and Google intelligently, concentrate on learning more rather than just completing the job somehow
Rocky
You can't climb up a ladder with your hands in your pockets.
|
|
|
|
|
helloise wrote: insertCommand.Parameters.Add("telephoneExtension", SqlDbType.NVarChar, 0, "TelephoneExtension");
Why would telephoneExtension have a length of 0?
And, you didn't execute the insertCommand you declared so the database will not get updated.
-- If this is a post that has been helpful to you, please vote for it. Thank you!
"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning."
--Rich Cook
|
|
|
|
|
I have the complete code here:
how do I excecute the insertCommand then, ie what is the code for it? thank you very much....
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace MyWindowsApp
{
public partial class AddAndUpdateForm : Form
{
public AddAndUpdateForm()
{
InitializeComponent();
}
private void LastnameTextBox_TextChanged(object sender, EventArgs e)
{
string lastname = LastnameTextBox.Text;
}
private void FirstnameTextBox_TextChanged(object sender, EventArgs e)
{
string firstname = FirstnameTextBox.Text;
}
private void NicknameTextBox_TextChanged(object sender, EventArgs e)
{
string nickname = NicknameTextBox.Text;
}
private void UserNameTextBox_TextChanged(object sender, EventArgs e)
{
string username = UserNameTextBox.Text;
}
private void TelExtTextBox_TextChanged(object sender, EventArgs e)
{
string telephoneExtension = TelExtTextBox.Text;
}
public void OKbutton_Click(object sender, EventArgs e)
{
SqlConnection mySqlConnection = new SqlConnection("server=ISS\\SQLEXPRESS;database=Staff;uid=sa;pwd=xbcprfly");
mySqlConnection.Open();
SqlCommand myCommand = mySqlConnection.CreateCommand();
myCommand.CommandText = "SELECT Lastname, Firstname, TelephoneExtension FROM Staff ORDER BY Lastname";
SqlDataAdapter mySqlDataAdapter = new SqlDataAdapter(myCommand);
DataSet myDataSet = new DataSet();
SqlCommand insertCommand = new SqlCommand("insert into Staff (Lastname,Firstname,TelephoneExtension) values (lastname,firstname,telephoneExtension)",mySqlConnection);
insertCommand.Parameters.Add("lastname", SqlDbType.NVarChar, 80, "Lastname");
insertCommand.Parameters.Add("firstname", SqlDbType.NVarChar, 80, "Firstname");
insertCommand.Parameters.Add("telephoneExtension", SqlDbType.NVarChar, 50, "TelephoneExtension");
//the following code is making me confused.
//myCommand.ExecuteNonQuery();
//mySqlDataAdapter.Fill(myDataSet, "Staff");
//mySqlDataAdapter.InsertCommand = insertCommand;
//mySqlDataAdapter.Update(myDataSet, "Staff");
//SqlCommand cmd = new SqlCommand(cmdStr, con);
//cmd.ExecuteNonQuery();
//SqlCommandBuilder mySqlCommandBuilder = new SqlCommandBuilder(mySqlDataAdapter);
this.Close();
}
private void Cancelbutton_Click(object sender, EventArgs e)
{
this.Close();
}
private void AddAndUpdate_Load(object sender, EventArgs e)
{
}
}
}
|
|
|
|
|
Hi all,
Any one know how to export datagridview columns(values) to MS Word using c#(windows application).
Thanks in advance
Know is Drop, Unknown is Ocean
|
|
|
|
|
You can use word object library to create new word document and put some text in it so iterate through all the rows of datagridview and put the text in word document.
|
|
|
|
|
Thanks for your suggestion, i need some sample code to understand this. Plz guid me.
Know is Drop, Unknown is Ocean
|
|
|
|
|
|
Thanks for your help. i found the solution.
Know is Drop, Unknown is Ocean
|
|
|
|
|
Hello friends,
I have developed many controls for my Window based application in C# .net. However i want to know whether i can utilise those controls on a web page. I have tried but so far no success.
Regards
Amit
|
|
|
|
|
yes you can do so by making dll of your control
and embedding your windows contol to htmls object tag.
rahul
|
|
|
|
|
Hello Friends,
I want to print contents of my Crystal report .Net to a Generic text Only Printer say an Epson 300+. But some how my printing gets disturbed.This happens only when my printer is using the Generic Text Only driver. My main concern is to print the report as fast as possible.
Thanks
Amit Kadam
|
|
|
|
|
Hi,
I have to compare MS Word Documents ie., the original document is to be compared with the same document after some editing and the process should be able to show the changes made. Please help me. The code should be in C#
thanx,
Nitin.
Nitin Raj Bidkikar
|
|
|
|
|
|
Hi,
Iam able to merge MS Word documents using c#. For using this code i have to select each and every Word document to be merged. Can any one tell me how to merge all the documents present in a folder at one go.
thanx
Nitin
Nitin Raj Bidkikar
|
|
|
|
|
Why you send same things with different titles
from your questions this post and your post about the zips are the same problem!
|
|
|
|
|
Hi,
I have to unzip multiple folders present in a single folder using c#. I have the code for doing this and it is working fine. For using this code I have to select the file that is to be unzipped and then after unziping it I have to select the next zip file and unzip it and so on. This is a very long process. Can anyone tell me how to unzip all the zip folders present in the parent folder at one go.
thanx
Nitin.
Nitin Raj Bidkikar
|
|
|
|
|