|
|
|
Hi,
I tried to save some information in an user.config file. I tried to save a hashtable, but it doesn't work. Thats why I tried to save an arraylist and it works. After that I would like to save a NameValueCollection, but this isn't saved like the arraylist?!?! WHY????
[CSHARP]
public System.Collections.ArrayList Setting
{
get
{
if (mySettings == null)
mySettings = new Specifications.Settings1();
return mySettings.Table;
}
set
{
if (mySettings == null)
mySettings = new Specifications.Settings1();
mySettings.Table = value;
mySettings.Save();
}
}
public System.Collections.Specialized.NameValueCollection Setting2
{
get
{
if (mySettings == null)
mySettings = new Specifications.Settings1();
return mySettings.Table2;
}
set
{
if (mySettings == null)
mySettings = new Specifications.Settings1();
mySettings.Table2 = value;
mySettings.Save();
}
}
[/CSHARP]
|
|
|
|
|
As I read somewhere else, the type namevaluecollection doesn't support xml serialization. thats why it doesn't work.
Does someone know, if there is another type, which supports xml serialization and can be used like namevaluecollection?!?
|
|
|
|
|
Use the object browser to view the different classes in System.Collections to find out which collections implement ISerializable.
|
|
|
|
|
I'm trying to manually create an Isolated storage which is associated with a particular type.
IN a pseudo code like that
using System;
using System.IO.IsolatedStorage;
class AType
{
}
class ISTest
{
public static void Main(string[] arg)
{
Type t = typeof(AType);
IsolatedStorageFile isf = IsolatedStorageFile.GetStore(
IsolatedStorageScope.Assembly | IsolatedStorageScope.User,
null,
t.Assembly.Evidence);
Console.WriteLine("Done");
}
}
That throws undecypherable error.
I try to use reflector to see what:
IsolatedStorageFile.GetUserStoreForAssembly()
does, but I was none the wiser... :-/
Any tip on how to create IsolatedStorage associated with an arbitrary assembly (given as an argument)?
|
|
|
|
|
How about IsolatedStorageFile.GetUserStoreForAssembly() ? Or from Reflector, remove that 't.Assembly.Evidence' bit and replace with null .
|
|
|
|
|
Not so
Because I write this code in a utility class to read / write / store configuration file.
<t>IsolatedStorageFile.GetUserStoreForAssembly() will use the assembly where this utility method is written instead of the assembly that try to save its conf file!
Do you see what I mean? I'm not sure to be clear...
|
|
|
|
|
I have a method that accepts an SQLDbType and an object.
I would like it the check if that object can be cast into the SQLDbType.
like so:
<br />
public void Thingy(SqlDbType dataType, object value)<br />
{<br />
if ()<br />
{<br />
}<br />
else<br />
{<br />
}<br />
}<br />
How would i go about doing this ?
Thanks.
|
|
|
|
|
Hi,
if (value is SqlDbType) {
}
|
|
|
|
|
Thanks ,
My next questions is:
So how then would I cast it to the specific data type of dataType (passed as a method argument/parameter)?
<br />
(dataType(value)) does not seem to work
nor does
<br />
(SQLDbType.dataType(value)) <br />
Cheers.
|
|
|
|
|
Hello,
<code>
public SqlDbType ConvertObjectToSqlDbType(object o)
{
return o as SqlDbType;
}
{
Object myobject = ????;
SqlDbType myvalue = ConvertObjectToSqlDbType(myobject)
if(myvalue!=null)
{
//Use it!
}
}
</code>
Hope that helps you.
All the best,
Martin
-- modified at 5:46 Friday 21st July, 2006
|
|
|
|
|
This won't function because SqlDbType is a value type.
|
|
|
|
|
Sorry if im not understanding what your getting at but what i want to do is pass an SQLDataType (like varchar or bigint) and an object then if the value castable to that type then cast it.
so value does not become just SQLDbType it becomes SQLDbType.bigint if the values passed where like so:
myMethod(SQLDataType.bigint, "400893");
or a varchar if you did this:
myMethod(SQLDataType.varchar, "ScoobyDoo");
I hope that makes sence (and is possible??)
Thanks again.
|
|
|
|
|
If you have checked whether value is really of type SqlDbtype the following is safe to use:
SqlDbType type = (SqlDbType)value;
|
|
|
|
|
Robert Rohde wrote: If you have checked whether value is really of type SqlDbtype the following is safe to use:
SqlDbType type = (SqlDbType)value;
Sorry if im getting the wrong end of the stick here...
But that code looks like is alters the value of type to = the value of value cast to an SQLDbType.
What I'm after is value to be cast from an object to the SQLDbType described by dataDype in the argument.
Or is that what it does do and I'm just misunderstanding the code.
-- modified at 6:02 Friday 21st July, 2006
|
|
|
|
|
No I don't get what you try to do .
The dataType parameter isn't a Type. Its a concrete value which is one of the values of the SqlDbType enumeration. What do you want to do with the object after being 'casted'. Probably then I understand what you actually are trying to do...
|
|
|
|
|
Here is a more fleshed out version... its part of an SQL "helper" type class this method is for adding parameters:
public void AddParameter(string name, SqlDbType dataType, object value)
{
if (name[0] != '@')
name.Insert(0,"@");
_SQLcmd.Parameters.Add(new SqlParameter(name, dataType));
_SQLcmd.Parameters[name].Value = value;
}
This works (well it compiles) but I want an IF clause in there so it only tries the last 2 lines IF the "value" object is castable to the SQLDbType defined by dataType.
Hope that helps.
And thanks again.
|
|
|
|
|
Hi again,
ok now I understand. I think you will have to make a swtich and test it for each type separately. At least I don't know any other way to do it.
You should also correct your Insert call:
if (name[0] != '@')
name = name.Insert(0,"@");
Insert doesn't change the instance name (because string is immutable) but returns a new instance.
|
|
|
|
|
hy,
one of the ways you can achieve that is to use exceptions, like this
try
{
//do the cast
}
catch(Exception)
{
//complain
}
using Exception in catch you catch all the exceptions that can occur. Of course you can only catch the InvalidCastException but that's your choice.
Hope it helps.
Do your best to be the best
|
|
|
|
|
Hi,
I have created a simple usercontrol which holds a panel. I drag this self made control to a window form. What i would like is to drag items from the toolbox to this usercontrol. i.e. drag a textbox to the panel on the usercontrol. But this is not working, the textbox is added to the window form instead of the panel from the user control.
So how can i make this happen why does the panel loose it's ability to add items that a dragged from the toolbox once the panel is part of a user control. Note i want to make the drag/drap happen at design time so just like it works normally.
|
|
|
|
|
Hello
Usercontrols don't handle drag/drop events by themselves. You have to do it maually and check the DesignMode boolean value to see if this drag/drop event is at design time or at run time.
Also there is Control.ControlsAdded event which you might want to handle as well
A better approach -if it doesn't contraindicate your goal from the control- is to inherit it from another Control similar to yours -eg. MenuStrip, ToolStrip, StatusStip, ToolStripContainer, etc..- Then it'll take care of everything for you. You just have to add a final touch to the code
Regards
|
|
|
|
|
Hi everyone
I was thinking is it possible to develop a application in c# that can intercept a telephone number using a dialup modem every time a phone call comes thru answered or unanswered the app should be able to log the number.
Thanks in Advance!
-- modified at 3:48 Friday 21st July, 2006
|
|
|
|
|
I think you can start to search there:
http://www.codeproject.com/useritems/IVR.asp
|
|
|
|
|
i know that this question doesn´t belong here, but i always get perfect answers here.
i´m working with reporting services and i have to make some graphs and i really don´t know how. there are only 2 report types - tabular and matrix. i also have problem with drill down option when using matrix, it´s not working correctly, i mean it´s hiding rows and columns, but it´s not sumarizing values.
cellardoor
cellardoor
|
|
|
|