|
You need to reference all necessary assemblies (in this case, mscorlib.dll which is always referenced unless you tell the compiler otherwise) and import the System namespace:
using System;
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
I am able to do that...
after that also i am unable to convert DBNull value to decimal...
I have a decimal , if nothing is there in that i need to assign a dbnull value to that , but i am not able to do that
Once again thanks for the immediate response
|
|
|
|
|
Because DBNull.IConvertible.ToDecimal always throws an InvalidCastException . But I answered what you asked.
You might want to be more specific about what you're trying to do. If you need to insert a null value for a decimal field in a database, then you actually use DBNull.Value , not the decimal equivalent (which isn't even possible since value types - such as the primative types - can't be null).
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Is there anyway i can do that......
|
|
|
|
|
If you use parameterized queryies for example, you could use that as the value:
SqlCommand cmd = sqlConnection1.CreateCommand();
cmd.CommandText = "UPDATE MyTable SET DecimalField = @DecimalField WHERE ID = 1";
SqlParameter decimalField = cmd.Parameters.Add("@DecimalField", SqlDbType.Decimal);
decimalField.Value = myDecimal == 0m ? DBNull.Value : myDecimal;
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Hi Heath Stewart
Could u let me know the solution for this
I have a web page which contains two frames, I am redirecting the user to login page once session timeout, the problem in both the frames I am getting the login page. could anybody let me know how can i handle so that it will redirect to login page with out any frames....
|
|
|
|
|
This is a common problem with frames, which is why almost all web sites do not use them today. I would recommend designing your site using tables to layout your page with included components like headers, footers, and navigation bars.
If you insist on frames, you will have more problems. Make sure you use the target attribute of the A tab wisely.
As far as deirecting a user to a single login page, this isn't possible using the .NET FCL's authentication modules. You would have to write your own authentication module that takes target frames into account. The ASP.NET authentication modules do not do this.
For more information on how to do this, read about IHttpModule and the existing authentication modules like FormsAuthenticationModule to see how they work, even using ildasm.exe that comes with the .NET SDK (if you know how to read IL) or ".NET Reflector", which you can google for (both a disassembler and decompiler with a nice interface - I currently do not have the link available since I'm on vacation).
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Hi
have a problem
Desc:
I am populating a window from parent window, i will perform some action on the child window and i will click OK button, once i click OK i need to pass a server side created object back to parent window.can you let me know how i can do that?
Thanks in advance
|
|
|
|
|
You can't. Once again, HTTP is simple client request/server response. The best you could do is pull the server from the client to watch for changes using the HTTPXML component or the WebService behavior, both supported only by Internet Explorer (Mozilla has a couple of possibilities as well).
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Please can you let me know how can i do that? ii have never worked on HTTPXML COMPONENT
|
|
|
|
|
|
Does anyone know how to call an external program in C#?
Thanks,
Tim Cole
|
|
|
|
|
|
|
Hi,
I have Scripting.DictionaryClass instance passed back to one of my methods from a COM object. I can see that this DictionaryClass instance has 4 items inside it. How can I retrieve the key/value pairs from this object ? I've tried cycling through it via an IEnumerator object but I get an "Invalid cast" exception. I've tried casting to to a System.Collections.Dictionary object but that doesn't seem to work either. I've tried using the Scripting.Dictionary.Items() method but results in an invalid cast also. There are also no getters/setter nor can I index into this object. Anyone have any other solutions ? Thanks in advance...
-Pete
|
|
|
|
|
The Scripting.Dictionary has nothing to do with the .NET FCL, so it doesn't implement IDictionary . It is an RCW (Runtime Callable Wrapper) to a COM object and you must use the COM methods and properties it exposes. The typelib importer (tlbimp.exe) does, however, provide the GetEnumerator which enumerates over the keys, but this is only defined by the DictionaryClass (though Keys() would as well since it's actually an object[] array that you could cast to IEnumerable ).
Take a look at this example code:
using System;
using Interop.Scripting;
public class Test
{
static void Main()
{
IDictionary dict = new DictionaryClass();
Add(dict, "a", 1);
Add(dict, "b", 2);
Add(dict, "c", 3);
object[] keys = (object[])dict.Keys();
for (int i=0; i<keys.Length; i++)
{
object key = keys[i];
object value = dict.get_Item(ref key);
Console.WriteLine("{0}: {1}", key, value);
}
object a = "a";
Console.WriteLine("\na={0}", dict.get_Item(ref a));
}
static void Add(IDictionary dict, object key, object value)
{
dict.Add(ref key, ref value);
}
} The only reason I don't use a foreach loop (uses the IEnumerable implementation) is because the key variable would be read-only, which you can't use with a ref , which is required to call get_Item .
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Wow ! Thanks for the quick and very clear reply. You've helped me understand my problem thanks. I just have one quick (and rather silly) question for you. Where can I find the Interop.Scripting assembly ? I can't seem to find it anywhere on my system. I've done a websearch and found a file called "Interop.Scripting.dll" and I managed to add it in to my projects. However when I try to reference it the compiler complains that it can't see it. What am I doing wrong ?
-Pete
|
|
|
|
|
It's the namespace of the interop assembly. I generated the interop assembly using:
tlbimp.exe /out:Interop.Scripting.dll scrrun.dll Chances are that you already have it since you were asking about it. VS.NET creates these automatically when you reference a COM server. If that's not the namespace it generated (though it should be), just change it to whatever is appropriate.
Also note that IDictionary here is Interop.Scripting.IDictionary, Interop.Scripting , not System.Collections.IDictionary, mscorlib . If you have both namespaces imported in your source file, you either need to change the scripting IDictionary to DictionaryClass , fully qualify the type, or use an alias like:
using IDict = Interop.Scripting.IDictionary; Then use IDict instead of IDictionary .
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Yep that worked. Thanks a million Heath. I really appreciate all your help. However I have one more quick question. I was looking at your code and you seem to have methods that my version of Interop.Scripting does not. You have a get_Item() method in your DictionaryClass while I don't. I only have the following methods:
Add()
Equals()
Exists()
get_HashVal()
GetEnumerator()
GetHashCode()
GetType()
Items()
Keys()
let_Item
Remove()
RemoveAll()
set_Key()
ToString()
Does this mean I have a different version then you ?
|
|
|
|
|
If you're using IntelliSense, you won't see it. It's defined in the assembly, however. You can't use the Item property because C# can not "call" a property that takes parameters, except for the indexer (which Item is not).
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Wow ! Thanks Heath. I owe you one; a BIG one. Thank you so much for all your help. You've made my day !
|
|
|
|
|
Hi!
Being given:
- a Source.doc file
- a variable myRange containg a Range (in the matter fact a paragraph taken from the Source file); this paragraph can contain pictures, not only plain text
- an empty Target.rtf file,
my problem is:
How can I paste the whole content of myRange into the Target file? (...because I want it saved in rtf format)
Should I use the Word Selection object or the Clipboard or what else? How?
Thanx!
--Miha
|
|
|
|
|
You would need to use the Selection object, yes. This can give you a Range which you can use or replace. I would suggest looking at the object model documentation in MSDN Online[^]., though you'll probably get better help if you have installed the developer help files with Office. The stuff on MSDN doesn't contain a very good TOC (table of contents) for the object model documentation. The developer help files (can be installed with any version of Office, IIRC) will be much more help.
Keep in mind that while those examples typically use VB (a COM client language), the same applies for you since you've created an (or are using an existing) interop assembly that wraps the COM objects, enums, and members (a Runtime Callable Wrapper, or RCW). While parameters may typically be declared as object or ref object , you still pass in the right objects (or a reference to them using ref someObjectInstance ) according to what the object model documentation says.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Hello,
Using C# on a web form with a textbox for the user to enter a word and then click on a button to have the word entered into a listbox. After the user has entered as many words as they wish they can then click on another button to have all of the words in the listbox processed.
My question is: how do I retreive the words from the listbox?
I would think I could loop through the listbox and get each word but I am not finding anything like this in my searches.
For (int i = 0; i < Listbox1.Count; i = i+1)
{
wordlist[i] = Listbox1.?????;
//processing code here
}
Can someone aim me in the right direction?
Regards,
Bill Antonacchio
|
|
|
|
|
for(int i=0; i<listBox1.Items.Count; i++)
{
wordlist[i] = listBox1.Items[i];
}
#include "witty_sig.h"
|
|
|
|