|
I'm replying for myself but I located the bug.
The caps object wasn't intialized!
Shimi
|
|
|
|
|
Hi
I am writing code which accepts an array of objects, converts them to XML and loads them into a dataset.
My problem is that when the XML is created, it does not contain an indication of the data types of the fields. As a result, all the data types of the columns in the dataset are System.String.
Is there a way to force creation of shcemea when creating the XML string?
Here is the code:
[Serializable]
[XmlType("MyClass")]
public class MyClass
{
[XmlAttribute("IntField")]
public int IntField;
[XmlAttribute("StringField")]
public string StringField;
[XmlAttribute("ByteField")]
public byte ByteField;
public MyClass() {}
}
string xmlString;
System.Xml.Serialization.XmlSerializer xmlSer;
XmlWriter xmlWriter;
MyClass myObj = new MyClass();
StringWriter sw = new StringWriter();
myObj.IntField = 1;
myObj.StringField = "a string...";
myObj.ByteField = 2;
xmlWriter = new XmlTextWriter(sw);
xmlSer = new XmlSerializer(typeof(MyClass));
xmlSer.Serialize(xmlWriter,myObj);
xmlString = sw.ToString();
// at this point the xmlString looks as follows:
//"
//<myclass xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" intfield="1" stringfield="a string..." bytefield="2">"
DataSet ds = new DataSet();
StringReader sr = new StringReader(xmlString);
ds.ReadXml(sr);
// At this point ds.Tables[0].Columns[0].DataType.ToString() returns System.String instead of System.32
|
|
|
|
|
XML serialization using the XmlSerializer always serializes to strings (that's all XML can contains) but deserializes the string back to the Types of the properties with which they map. When you read this XML fragment into a DataSet , the DataSet has no idea what it is reading and will assume that all the columns are simply strings.
In order to coerce the DataSet to use a schema, you can either create a DataSet schema using the DataSet designer in VS.NET, or just type one manually yourself and read that schema in with DataSet.ReadXmlSchema , then use DataSet.ReadXml .
An even better way is to create a strongly-typed DataSet using the VS.NET DataSet designer (right-click on project or project folder, select Add->Add New Item and select DataSet) and use that instead of DataSet :
MyDataSet ds = new MyDataSet();
StringReader sr = new StringReader(xmlString);
ds.ReadXml(sr); This way, the DataSet object is initialized with all the necessary table and column information and you can refer to columns by name without having to cast to the necessary data type.
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
i see some third party menus and microsoft access place controls in menu like textbox control
how can i do that in c#
i mean if i have to use hooking
hook what ?
thanks in advance
|
|
|
|
|
I tried to ask this earlier, but something went crunch.
I want to have my application start each time the computer boots up. Anybody know how to do this or where to find out how?
Thanks in advance
Joe
|
|
|
|
|
pardue,
You can use windows registry, all you need to do is just create a string value pointed to your .exe file in the following windows registry key :[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run]
for example:
(For all users)
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run]
"myApp"="\"C:\\MYAPP\\myApp.exe\""
(For Current users)
[HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Run]
"myApp"="\"C:\\MYAPP\\myApp.exe\""
you can do this via programming or just by making a .reg file and then run it. another simple way you can use is to create an icon for your exe file in the windows startup folder.
|
|
|
|
|
shaun77 wrote:
another simple way you can use is to create an icon for your exe file in the windows startup folder.
A shortcut, actually, not an "icon". The Startup folder is also in Start->Programs->Startup, which is also scoped for either the user or the system depending on the platform (Windows vs. Windows NT). The best way would be to create a Windows Installer project and use the Shortcuts designer there. The Windows Installer runtime automatically determines the platform and uses a global shortcut, or it can use a user shortcut (if available) depending on your options.
For examples, on Windows NT-based platforms (NT4, 2000, XP, 2003, and all future versions) except for NT4 (everything was in C:\Winnt\Profiles), you can use either C:\Documents and Settings\All Users\Start Menu\Programs\Startup for all users, or C:\Documents and Settings\username\Start Menu\Programs\Startup for a specific user.
For Windows, this is typically C:\Windows\Start Menu\Programs\Startup.
Of course, replace the C: drive with your system drive, but this is usually C:. Again, if you use a Windows Installer project, it automatically resolves all special shell folders.
To add a Windows Installer project to your solution (which can then take advantage of build targets for your other proejct(s)), right-click on your solution, select "Add->New Project", select "Setup and Deployment Projects", then "Setup Project". Give it a name and click "OK".
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
Many thanks! I wish I could buy you guys lunch.
I was soooo close and didn't even realize it. I already had a shortcut installed in the start menu, but following your suggestions I did the following:
In my installer project I openned the File System Editor and under the User's Start Menu folder I added a Programs folder and under that I added a Startup folder and in that I added a shortcut to the active project.
This works on 98, 2000, and XP.
My client will love me even more.
Thanks again,
Joe
|
|
|
|
|
Hello, Sir
How to get the target that *.lnk link to
Thank You.
|
|
|
|
|
Hi,
Im developing a project which consists of a client which sends images to a server. The server must store these images in a database, and I am having a multitude of problems. I first tried creating a web-service which accepted the image as a parameter in a web method, but it would appear that System.Drawing.Image.Bitmap is not serializable - it generates an XML Serialization error. I then thought I would try and access the database directly and just store add images using an INSERT command, but I am getting an error message that the 'object' (I believe this refers to the image object) must implement IConvertable.
Can anyone help me at all - I've been trying to sort this for the last week, and I really need to sort it.
Thanks in advance
Peter
|
|
|
|
|
Adding images to a database has been covered numerous times in the past. Please use the Search Comments link above and search for previous solutions, such as these found in a recent thread: http://www.codeproject.com/script/comments/forums.asp?msg=704229&forumid=1649&XtraIDs=1649&searchkw=database+image&sd=10%2F22%2F2003&ed=1%2F20%2F2004#xx704229xx[^].
As far as sending images (either Image orBitmap , a derivative of Image , neither of which are serializable), most implementations use a MemoryStream (or another Stream like FileStream , especially if the images were already saved to disk) to save the images to a buffer (a byte[] array), which is serializable (since Array is serializable).
Either way, once your image gets deserialized on the server, you still have to insert it into the database. Depending on your implementation requirements, you might actually be better off storing the image on the file system and inserting a file reference (like the URL to access it remotely, which you can always use Page.MapPath to get the file system path) into the database. This way, if you want to display the images in a web page, you don't have to extract them first or use a page to dynamically extract and stream them out using a different content-type than a normal page (ex: .aspx file).
For a good example using SQL Server, see C# Photo Album Viewer[^]. If this is for use on a server, I highly recommend that you do not use Access. Use a real RDBMS that implements ACID properties like SQL Server or the MSDE (a connection-limited version of SQL Server). You can find more information about SQL Server at http://www.microsoft.com/sql/default.asp[^] or download the MSDE for free at http://www.microsoft.com/sql/msde/default.asp[^]. This way, you can take part in transaction processing, stored procedures, triggers, and much more with much greater efficiency than a file-based database like MDB files.
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
Thanks once again for your help Heath!!
I did use the search facility for the message boards and general articles, but I was unable to find something which actually stored the image in the database, not just a referance. I will consider doing this though in my implementation.
I am using MS SQL Server - not access, and I will carefully go through the mentioned articles.
Thankyou once again - I will battle on!
Peter
|
|
|
|
|
You can convert it to a byte[] before send to the server and then store it directly.
public StorePhoto(byte[] photoContent)
{
.......
SqlParameter param1 = new SqlParameter("@photo",SqlDbType.Image);
param1.Direction = ParameterDirection.Input;
param1.Value = photoContent;
.......
}
|
|
|
|
|
Since I may transfer to C# from Visual C++, is there any memory management in C# like pointers, since I don't like them too much and is there anything new in it... maybe a website would help explain it better if it dealed with these kinds of things...
Actual Linux Penguins were harmed in the creation of this message.
|
|
|
|
|
Sure there's a web site...this one! There's also http://msdn.microsoft.com[^], the Microsoft Developer Network, and many, many other sites.
First of all, understand that C# is merely one of many languages that target the Common Language Runtime, the runtime of the .NET Framework (and like all languages, the compiler produces very similar Intermediate Language, or IL, making assemblies available across languages and platforms). Code that runs in the CLR is often called managed code because the CLR manages all memory, so don't use pointers unless you have to! This requires an unsafe context.
In .NET, all objects are already reference Types and inherit from System.Object , except for enums, structs, and intrinsic types like Int32 (int ), Byte (byte ), et. al., which derive from ValueType (which also derives from Object , but is handled different by the CLR). These are allocated on the stack. Some managed languages like C# can use unsafe contexts for things like pointer manipulation, but this is usually only done when processing image pixels. For the most part, don't use it and just let the CLR do its job: managed memory.
The best thing is to start reading the .NET Framework SDK, starting with the Overview[^].
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
Hi all
I wrote a large MFC application and recently began to convert it to .NET framework. I do this step-by-step by rewriting some parts and components written in MFC into C#. Now I have application written in MFC with a lot of C# components talking between them using com-interop.
But now i want to perform some serious testing. I've tried some available products such as Rational Quantify and DevPartner and all of them had problem to handle with my app because it written both in MFC and C#.
What is the best way to test such app (CPU, memory etc.)?
Can anybody recomend me about some other monitoring product?
thanks.
|
|
|
|
|
2 words: Performance counters There are a whole host of them.
leppie::AllocCPArticle("Zee blog"); Seen on my Campus BBS: Linux is free...coz no-one wants to pay for it.
|
|
|
|
|
Hi Every Body,
Just imagine you have two application, one is been written in C# and another is by delphi.
I just wanted to know, if i create a report in the c# and i set everything ( data source,parameter,...) in the use .net emviroment, can the other parties based on delphi open my report and change some property (for example passing parameters) and show it up?
any hint is appreciated.
|
|
|
|
|
I have an image processing application which is using very complex image processing algorithms.
i am using unsafe code for reading and writing image for performance reasons.
But my application is taking tooo much memory like 120 MB or so.. What to do?
should i call GC.Collect manually?? any other suggestions.
my application heavily relies on string handling, Hashtables and ArrayList
Muhammad Shoaib Khan
http://geocities.com/lansolution
|
|
|
|
|
When you're finished with an Image , call Dispose . If you're using the Graphics class, also call Dispose on that when finished. Dispose is a method exposed by controls implementing IDisposable (others could have such a method, too, but the CLR doesn't recognize it then). It typically is used to free native resources which many of the .NET classes (especially Windows Forms controls) use. In this case, native resources are used both for Image and Graphics . Doing this eliminates the need for garbage collection (at least regarding objects of these two Types) - Dispose calls GC.SuppressFinalize for each object when finished.
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
hi;
i have bitmap with 24bpp pixel format, i need to convert it into 1bppIndexed, coz i need to read it in 1 and 0 (white and black)
can anyone provide a method 4 that?
i'll be thankfull
FiDz
|
|
|
|
|
|
1. You will need to create the Indexed ColorMap (i dunno how).
2. Then apply a filter reading each pixels color and converting to either 0 or 1. (btw the image quality will very crap, not sure if it would usefull, unless u are doing fingerprints)
leppie::AllocCPArticle("Zee blog"); Seen on my Campus BBS: Linux is free...coz no-one wants to pay for it.
|
|
|
|
|
Hi.
I'm working on a small Guestbook component. I want to make this component as good as possible and realy re-usable. I have a public class called GuestbookLogic exposing all the methods needed to get messages, add new messages and so on. The GuestbookLogic class have a prive property called Dalc. The Dalc property is of type IDalc.
IDalc is a public interface defining all the methods needed by the Data Access Layer Component to be compatible with the bussines logic. In the component i have two implementations of IDalc, SqlDalc and OleDbDalc. The reason i did this was to enable the users of the component to implement any DALC. For instance, if you want to use XML as your data layer, you could create a XmlDalc by implementing IDalc.
My problem is how you tell the bussines logic which implementation of IDalc to use. At the moment i have some logic in the get {} method of the private IDalc property. What it does is to check if the private dalc == null, if it is, then create a new instance of IDalc based on values in app/web.config. It creates the instance like this:
<br />
dalc = (IDalc)System.Activator.CreateInstance(Type.GetType(System.Configuration.ConfigurationSettings.AppSettings["GreIT.Guestbook.Dalc"])); <br />
The GreIT.Guestbook.Dalc propery have this value: "GreIT.Guestbook.SqlDalc, GreIT".
My question is: say you use this component on a ASP.NET app. Would using System.Activator be a performance issue? Do you have any other ideas on how to plug in the IDalc implementation? I could have a set of pre-defines properties, and then have some logic like this.
<br />
string dalcSetting = System.Configuration.ConfigurationSettings.AppSettings["dalc"];<br />
<br />
if(dalcSettings.Equals("Sql")) dalc = new SqlDalc(); <br />
else dalc = new OleDbDalc();<br />
The problem with this implementation is that the developers using the component wouldn't be able to plug in IDalc implementations of their own.
|
|
|
|
|
The AppSettings - like all configuration sections after initial reads - are cached so accessing this won't cause the app to parse XML each time. Using Activator.CreateInstance is also fairly common, and even though it require a few more cycles to instantiate the Type, this would be negligable for code that isn't burdened with lots of requests. If this is the case, you could instead cache the Type in an Application state variable. That would at least save you a little time. Since any changes to the .config result in the AppDomain for the web application to reload, you wouldn't even have to worry about cleaning up the application state variable. Just put some check for this variable in your code like so:
if (Application["DalcType"] == null)
{
Application["DalcType"] = Type.GetType(...);
} The Application reference you can get depending on where you request it, whether that's in a Page or from the HttpContext.Current reference. This would cut down the amount of code required to execute to get the Type, thus boosting performance some.
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|