|
What about using an overload that way if it is passed in as something other then a valid DateTime object it will get treated by the overlaoded method and there you can try parsing it manually:
<code>
[WebMethod]
public ReturnList GetList(string id, string fromDate)
{
}
[WebMethod]
public ReturnList GetList(string id, System.DateTime fromDate)
{
}
</code> Worth a try ... hth
|
|
|
|
|
Hi,
I would like to make a column of listview, invisible. by setting width property to zero, I can achieve this.
But, when I am trying to increase or decrease the width of previous or next column with mouse drag then the hiden column automatically get displayed.
Any solution for that ?
Like
making that column invisible. OR
making mannual resizing of any column as false
Please help me in this regard.
Thanks in advance
|
|
|
|
|
You can override the painthandler; you got some extra control when owner-drawing. It may be more suitable to put the contents of the hidden column somewhere else. Like a Dictionary , linking each value to a ListViewItem
I are troll
|
|
|
|
|
Object cannot be cast from DBNull to other types.
what does this mean
|
|
|
|
|
benson.misi wrote: Object cannot be cast from DBNull to other types
this means... Object cannot be cast from DBNull to other types
Life goes very fast. Tomorrow, today is already yesterday.
|
|
|
|
|
Maybe you could post the code that cause this error? This will help us to help you...
|
|
|
|
|
'Help' is not a great subject: please read posting guidelines [^] before actually posting.
benson.misi wrote: Object cannot be cast from DBNull to other types.
what does this mean
You're possibly relying on a db antry that, instead, is missing.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
I'm guessing you are doing something like:
if(row["blah"]==null)
and it should be
if (row["blah"] == DBNull.Value)
?
|
|
|
|
|
Hi all,
Hope I am posting this in the right forum.
I seem to be having a problem when using serialization and web services.
Scenario:
I have built a web service which includes a multitude of web methods. All the web methods have various parameters, but one parameter which they all have in common is an 'object' parameter. This is due to the fact that the web service works differently according to the type of object being passed into it.
Now as for the objects, I have constructed a set of custom classes which satisfy my need. For example's sake, let us say we have:
Teacher class
Student Class
LectureRoom Class
Lecture Class
We will call these the "School Package classes"
I am then wrapping these classes within other custom classes which I use not only to transport my objects around but also to keep track of statuses etc. Example:
Request Class
Response Class
The school package classes would be serialized and saved within the request or response class. So effectively, the objects which the web service really sees are the request and response classes which will in turn have the school package classes inside of them.
The Problem:
The problem is found when a school package object is passed within the response and request object. On deserialisation or transportation of these objects, the web service always throws an exception as follows:
{"System.Web.Services.Protocols.SoapException: Server was unable to process request. ---> System.InvalidOperationException: There was an error generating the XML document. ---> System.InvalidOperationException: The type <classname> was not expected. Use the XmlInclude or SoapInclude attribute to specify types that are not known statically.
From what I could gather and the research I have done, the problem lies with the web service not knowing of the object types at compile time.
Make Shift Solution:
For a quick and dirty solution I created methods within the web service which use the object types needed. For Example:
public void Junk(Student myStudent){}
This seemed to have worked, but is not what I want, as with about 40 custom classes, this is both horrible coding and very tedious.
I have also tried researching the xmlinclude and soapinclude found in the System.Xml.Serialization library, but dont really know how to use these. I have tried adding them above the web service class declaration and the web methods which use the objects in this format:
[XmlInclude(typeof(Student))]
But yet to no avail. I have officially run out of ideas and would greatly appreciate anyone who has experience or ideas regarding this problem.
Thank you very much in advance for your time and excuse the length of the post.
James Bason
|
|
|
|
|
How do you annotate your custom objects to make them serializable? Something like this? :
[System.Xml.Serialization.XmlTypeAttribute(Namespace = "http://namespace/", TypeName = "person")]
public class Person
{
private string _name;
[System.Xml.Serialization.XmlElementAttribute(ElementName = "name")]
public string Name { get { return _name; } }
}
And are you sure that you don't have any namespace-conflicts between your custom objects?
|
|
|
|
|
no at the moment the objects are as follows:
using System;
using System.Runtime.Serialization;
using Person;
namespace SchoolPackage
{
[Serializable()]
public class Student : ISerializable
{
private Person person;
private int intReference;
private int intReqTypeID;
private string strLastAlteredByUser;
private DateTime dteAlteredDate;
private Boolean blnIsDirty;
private Boolean blnIsNew;
private enum RequestType : int
{
Create = 1, Delete = 2, Update = 3, Execute = 4,
Retrieve = 5, RetrieveMultiple = 6
}
public Student(Person person, String user, int TypeID, int Reference)
{
this.person = person;
this.strLastAlteredByUser = user;
this.dteAlteredDate = DateTime.Now;
this.blnIsDirty = false;
this.blnIsNew = true;
this.intReqTypeID = TypeID;
this.intReference = Reference;
}
public Student(SerializationInfo info, StreamingContext ctxt)
{
person = (Person)info.GetValue("person", typeof(Person));
action = (string)info.GetValue("action", typeof(string));
intReference = (int)info.GetValue("intReference", typeof(int));
intReqTypeID = (int)info.GetValue("intReqTypeID", typeof(int));
}
public void GetObjectData(SerializationInfo info, StreamingContext ctxt)
{
info.AddValue("person", person);
info.AddValue("action", action);
info.AddValue("intReference", intReference);
info.AddValue("intReqTypeID", intReqTypeID);
}
}
|
|
|
|
|
System.Runtime.Serialization is used for binary serialization.
Since Webservices use Soap wich is xml, you should serialize objects to xml.
Read this article on msdn about XML Serialization with XML Web Services.
In your example, just import System.Xml.Serialization and add the annotation [System.Xml.Serialization.XmlTypeAttribute()].
And make public accessors to the members you want to be serialized.
using System;
using System.Runtime.Serialization;
using Person;
using System.Xml;
using System.Xml.Serialization;
namespace SchoolPackage
{
[System.Xml.Serialization.XmlTypeAttribute(Namespace = "http://www.x.com/namespace/", TypeName = "Student")]
public class Student
{
[System.Xml.Serialization.XmlElementAttribute(ElementName = "myCustomXmlElementName")]
public string StrLastAlteredByUser
{
get { return strLastAlteredByUser; }
set { strLastAlteredByUser = value; }
}
}
}
ps. personally I would let Student inherit Person
|
|
|
|
|
I have done as you suggested and am still getting the same error. The problem now I believe is the way I am serialising the object. I have made a custom class for this:
using System;
using System.Text;
namespace Helper
{
public class Serializer
{
public Serializer()
{
}
///
/// Method to deserialise an object from a string of hex characters
///
/// <param name="hex" />
/// <returns>the object which was deserialised
public Object DeserialiseObject(String hex)
{
System.IO.MemoryStream stream2;
System.Runtime.Serialization.Formatters.Binary.BinaryFormatter bformatter2
= new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();
byte[] array = HexStringToByteArray(hex);
stream2 = new System.IO.MemoryStream(array);
Object obj = bformatter2.Deserialize(stream2);
stream2.Close();
return obj;
}
///
/// Method to serialise an object into a hex string
///
/// <param name="temp" />
/// <returns>
public string serializeObject(Object temp)
{
//write it to stream
System.IO.MemoryStream stream2 = new System.IO.MemoryStream();
System.Runtime.Serialization.Formatters.Binary.BinaryFormatter bformatter2
= new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();
bformatter2.Serialize(stream2, temp);
byte[] array = new byte[stream2.Length];
array = stream2.ToArray();
String hex = ByteArrayToHexString(array);
stream2.Close();
return hex;
}
///
/// Helper to change a byte array to a hex string
///
/// <param name="Bytes" />
/// <returns>string of hex characters
private static string ByteArrayToHexString(byte[] Bytes)
{
StringBuilder Result;
string HexAlphabet = "0123456789ABCDEF";
Result = new StringBuilder();
foreach (byte B in Bytes)
{
Result.Append(HexAlphabet[(int)(B >> 4)]);
Result.Append(HexAlphabet[(int)(B & 0xF)]);
}
return Result.ToString();
}
///
/// Helper to change hex string to byte array
///
/// <param name="Hex" />
/// <returns>returns a byte array
private static byte[] HexStringToByteArray(string Hex)
{
byte[] Bytes;
int ByteLength;
string HexValue = "\x0\x1\x2\x3\x4\x5\x6\x7\x8\x9|||||||\xA\xB\xC\xD\xE\xF";
ByteLength = Hex.Length / 2;
Bytes = new byte[ByteLength];
for (int x = 0, i = 0; i < Hex.Length; i += 2, x += 1)
{
Bytes[x] = (byte)(HexValue[Char.ToUpper(Hex[i + 0]) - '0'] << 4);
Bytes[x] |= (byte)(HexValue[Char.ToUpper(Hex[i + 1]) - '0']);
}
return Bytes;
}
}
}
|
|
|
|
|
I have got to this point.
The classes are all now in this format:
using System;
using System.Collections;
using System.Xml.Serialization;
using System.Xml;
namespace Data.Package
{
[System.Xml.Serialization.XmlTypeAttribute(Namespace = "Data.Package", TypeName = "Changes")]
public class Changes
{
private Boolean blnIsDirty;
private Boolean blnIsNew;
public Changes()
{
this.blnIsDirty = false;
this.blnIsNew = true;
}
[System.Xml.Serialization.XmlElementAttribute(ElementName = "IsDirty")]
public Boolean IsDirty
{
get { return blnIsDirty; }
set { blnIsDirty = value; }
}
[System.Xml.Serialization.XmlElementAttribute(ElementName = "IsNew")]
public Boolean IsNew
{
get { return blnIsNew; }
set { blnIsNew = value; }
}
}
}
My serialization class is as follows:
using System;
using System.Text;
using System.Xml.Serialization;
using System.IO;
using System.Xml;
namespace Helper
{
public class Serializer
{
public Serializer()
{
}
public String serializeObject(Object pObject)
{
try
{
String XmlizedString = null;
MemoryStream memoryStream = new MemoryStream();
XmlSerializer xs = new XmlSerializer(pObject.GetType());
XmlTextWriter xmlTextWriter = new XmlTextWriter(memoryStream, Encoding.UTF8);
xs.Serialize(xmlTextWriter, pObject);
memoryStream = (MemoryStream)xmlTextWriter.BaseStream;
XmlizedString = UTF8ByteArrayToString(memoryStream.ToArray());
return XmlizedString;
}
catch (Exception e)
{
System.Console.WriteLine(e);
return null;
}
}
public Object deserializeObject(String pXmlizedString)
{
XmlSerializer xs = new XmlSerializer(typeof(Object));
MemoryStream memoryStream = new MemoryStream(StringToUTF8ByteArray(pXmlizedString));
XmlTextWriter xmlTextWriter = new XmlTextWriter(memoryStream, Encoding.UTF8);
return xs.Deserialize(memoryStream);
}
private String UTF8ByteArrayToString(Byte[] characters)
{
UTF8Encoding encoding = new UTF8Encoding();
String constructedString = encoding.GetString(characters);
return (constructedString);
}
private Byte[] StringToUTF8ByteArray(String pXmlString)
{
UTF8Encoding encoding = new UTF8Encoding();
Byte[] byteArray = encoding.GetBytes(pXmlString);
return byteArray;
}
}
}
I then create a new instance of serializer and pass it my Changes object. I have debugged through the serialization code and that works fine, its right after where it fails with the same exception that the type "Changes" was not expected.
Any ideas anyone ?
|
|
|
|
|
Hi
What i need to do is to get keyboard letters and "letter combinations" which is the core of my problem
for ex:
when i press alt + f4 i wnat to see alt f4 in the label
i have the code snippet
protected override void OnKeyDown(KeyEventArgs keyEvent)
{
label1.Text = "";
label1.Text=keyEvent.KeyCode.ToString();
}
Can anyone show me a way to do it please?
Thanks...
|
|
|
|
|
hmmmm seems suspicious... but I think KeyEventArgs has something to detect if buttons like alt, shift, ctrl are currently pressed.
Life goes very fast. Tomorrow, today is already yesterday.
|
|
|
|
|
forget the loop, loops seldom belong in an event handler.
Create one method that is used for both KeyDown and KeyUp events.
|
|
|
|
|
Check the value of keyEvent.Alt, it will be true if the alt key is held down.
|
|
|
|
|
Hi,
You can override the ProcessCmdKey() function in Control class like this :
protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
{
if (keyData == (Keys.Alt | Keys.F4))
{
//Your Code
}
return base.ProcessCmdKey(ref msg, keyData);
}
Hope this helps,
ramz_g
|
|
|
|
|
Hi guys,
I am facing the following problem:
my application is downloading large chunks of data and informs the user about it (how many bytes of total bytes... how many % already loaded and so on).
this work is done by a component that informs the form by rasing a event. within the method which gets executed by the event happens a updatePanel.Refresh() (a redraw of the panel that shows the information)
because that event gets fired reasonable often, the updatePanel is redrawn all the time.
when I try to move the windows of the application it doesnt work properly.
what must I do to stop the refresh of the updatePanel when the form is moved around?
any suggestions welcome
thansk
best regards
t
|
|
|
|
|
well for one I assume the work is being done on a separate thread?
You could try limiting the update with a timer or counter...
for example if your updating with every downloaded byte of data you could update with every KB of data, or you could use a timer and then update only if a certain period has elapsed, then reset the timer with each update.
Life goes very fast. Tomorrow, today is already yesterday.
|
|
|
|
|
Hi mate,
thanks for sharing your idea. helped me impementing a quick solution to the problem.
basically, i use a timer and the forms-move event. i start the timer when the form is moved and let the timer point to a method whichs sets a flag, that the form is on the move. works like a charm.
thanks
best regards
t
|
|
|
|
|
Hi,
How can i perform Alt+T operation through programming in c#.net 3.5 Windows application.
Thanks In Advance
--Naren
|
|
|
|
|
That would depend on what Alt-T does in your application.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
I want to open a topic using that
|
|
|
|