|
Glad to help. Good luck learning about SQL Server.
"You can have everything in life you want if you will just help enough other people get what they want." --Zig Ziglar
The Second EuroCPian Event will be in Brussels on the 4th of September
Can't manage to P/Invoke that Win32 API in .NET? Why not do interop the wiki way!
My Blog
|
|
|
|
|
SQL Server and the MSDE can run up to 16 instances, inclusive. That's 16 total between the two, since SQL Server and the MSDE share the same engine.
The default installation for the MSDE that comes on the VS.NET CDs/DVD is not the default (unnamed) instance. Last time I checked, it was VSdotNET.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Dear, Sir and Madam.
Please see my code
public class Test
{
public string name;
public string title;
public Test[] Tests;
}
If I get an Test object (name = x) in Test object,
how to know the path of x?
Is there the better way than looping the object?
Sorry for bad English.
Thank You.
|
|
|
|
|
You just have to recurse and construct the "path" yourself. This would be a very simple recursive loop to create.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Dear, Sir and Madam.
To compare integer use the following code
if (i==j) //i and j is integer
DoSomething();
If i and j is MemoryStream, how to compare them
Sorry for bad English.
Thank You.
|
|
|
|
|
Only primitive types and those that define the equality operators are comparable using == , otherwise a simple reference (whether i and j referenece the same object) is performed. Classes may also override Object.Equals ; if they don't, again simple reference equality is used.
Since MemoryStream nor its base class, Stream , define either of these, you must compare these byte-for-byte yourself:
public int Compare(MemoryStream a, MemoryStream b)
{
if (a == null && b == null) return 0;
else if (a == null || b == null) throw new ArgumentNullException(
a == null ? "a" : "b");
if (a.Length < b.Length) return -1;
else if (a.Length > b.Length) return 1;
byte buf;
while ((buf = a.ReadByte()) >= 0)
{
int diff = buf.CompareTo(b.ReadByte());
if (diff != 0) return diff;
}
return 0;
} As with most comparisons in the BCL, 0 is returned if the two streams are equal. a negative or positive integer value is returned depending on the conditions, which should be obvious from the code above.
Note that this is only an example, but should give you an idea of how to compare the MemoryStream s.
You could also P/Invoke the memcmp function, although this will hinder the portability of your code but will be very fast.
As I covered a few days ago with the same question (hint: it's a good idea to try searching for previous questions before posting), you can P/Invoke memcmp like so:
public sealed class ByteComparer
{
private ByteComparer();
public static int Compare(byte[] a, byte[] b)
{
return memcmp(a, b, new IntPtr(a.Length)).ToInt32();
}
[DllImport("msvcrt.dll")]
private static extern IntPtr memcmp(byte[] a, byte[] b, IntPtr count);
} This does a comparison using the native memcmp API if you just pass two byte[] arrays (which you can get easily using MemoryStream.ToArray ) into the static method Compare :
MemoryStream a = ...;
MemoryStream b = ...;
int diff = ByteComparer.Compare(a.ToArray(), b.ToArray());
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
It might be worth adding:
if( a == b )
return 0; in case anyone does try to do Compare( a, a ) . It might seem unlikely, but you have to consider aliasing.
Stability. What an interesting concept. -- Chris Maunder
|
|
|
|
|
Good idea. Might save quite a bit of time since the byte for byte comparison would run max(O(n)) just to return 0.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
|
First of all, this is best suited for a good abstract model. A Person class, for example, would define the common properties and derivative classes (like Executive , Manager , etc.) would define additional properties specific to them (perhaps even extend Person with a Supervisor class, and the latter two classes derive from Supervisor since they would ultimately have something in common).
If you want the PropertyGrid to display properties at runtime that aren't actually defined on the class, implement the ICustomTypeDescriptor on your class. For the most part, just call TypeDescriptor methods for each interface member implementation, passing true for the parameter typically called noCustomTypeDesc . For example:
TypeConverter ICustomTypeDescriptor.GetConverter()
{
return TypeDescriptor.GetConverter(this, true);
} For the two ICustomTypeDescriptor.GetProperties overloads, you return a PropertyDescriptorCollection with the defined properties and shadowed properties.
You can find more information about the ICustomTypeDescriptor in the .NET Framework SDK, but implementing will require understanding the .NET ComponentModel, so I suggest you read Enhancing Design-Time Support[^] in the .NET Framework SDK.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Hello...
I have a problem...
I want to delete a file but i cant delete it, it thwors an error an sais acces denied!
I have tried this...
string FileFullDest = "C:\test\test.dl";
FileInfo Delete = new FileInfo(FileFullDest);
Delete.Delete();
Don't know what else to do!
Anyone who can help me?
|
|
|
|
|
You can also use File.Delete , but the result is the same if you don't have the necessary file system permissions (for that particular file) or code access security (i.e., permission to delete any file via code in .NET).
Please be more descriptive. What is the exact exception type (ex: SecurityException , etc.) and message text? From where is the application that contains this code run (i.e., local computer, intranet server, etc.)?
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
it trows an IOException!
it sais -> the process cannot access the file "c:\test\test.dll" because it is being used by another process!
But isn't it possible to delete it anyway?
|
|
|
|
|
Not if another process is using it, no. Whatever process has loaded and mapped test.dll into its process space must be shutdown first. Operating systems are supposed to protected against this.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
And there is no way to stop the process at run time?
|
|
|
|
|
Yes, but you have to know what the process is. You also shouldn't just go stopping processes just so you can delete a file.
See the System.Diagnostics.Process class for a way to get a list of running processes. You'd have to enumerate them and then enumerate their Process.Modules property to find which process is using test.dll, then attempt to close it gracefully using Process.Close . If that doesn't work, use Process.Kill to terminate it.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
okay i try that!!
thansk!!
|
|
|
|
|
I sense impending disaster.
|
|
|
|
|
|
That you're trying to make a malicious program.
Jeremy Falcon
|
|
|
|
|
Actually, it was more to do with the fact that he appeared to blindly ignore some of Heath's advice.
Heath Stewart wrote:
You also shouldn't just go stopping processes just so you can delete a file.
After giving this warning, Heath answered the question to which
QzRz wrote:
okay i try that!!
"You can have everything in life you want if you will just help enough other people get what they want." --Zig Ziglar
The Second EuroCPian Event will be in Brussels on the 4th of September
Can't manage to P/Invoke that Win32 API in .NET? Why not do interop the wiki way!
My Blog
|
|
|
|
|
I am using the article Inserting XML formatted data into SQL Server 2000 By faisal abdul aziz as a template for some work I doing. I have create a class, in a separate class file, to cover the 'child' elements. I have called this Answers.cs.
The begining of the file looks like this:
using System;
using System.Xml.Serialization;
namespace SGC.Apps.Consultations
{
public class Answers
{
public Answers()
{
}
private int intQNo;
private int intAns;
[XmlAttribute]
public int Question_No {
get {
return this.intQNo;
}
set {
intQNo = value;
}
etc.....
In web form I have button_click event routine
private void Button1_Click(object sender, System.EventArgs e) {
if (Page.IsValid) {
XmlSerializer serlizer = new XmlSerializer(typeof(Replies));
int intCount = 2;
Answers[] ans = new Answers[intCount];
ans[1].Question_No = 3;
etc......
I get the error Object reference not set to an instance of an object
The highlighted line is 'ans[1].Question_No = 3;
Full error is [NullReferenceException: Object reference not set to an instance of an object]
Can anyone help with what stupid thing I am doing wrong?
cheers
Robert T Turner
South Gloucestershire Council
|
|
|
|
|
1: int intCount = 2;
2: Answers[] ans = new Answers[intCount];
3: ans[1].Question_No = 3;
I've numbered the lines above.
In line 2 all you are doing is reserving the space for the objects. You still have to create them. So after line 2 you need to do
ans[0] = new Answer();
Also, remeber that indexes in C# are zero-based. I don't know if you knew that, but it looked odd (line 3) that you were starting on index 1.
"You can have everything in life you want if you will just help enough other people get what they want." --Zig Ziglar
The Second EuroCPian Event will be in Brussels on the 4th of September
Can't manage to P/Invoke that Win32 API in .NET? Why not do interop the wiki way!
My Blog
|
|
|
|
|
Colin Angus Mackay wrote:
Also, remeber that indexes in C# are zero-based.
To be complete, indexes in .NET are all zero-based.
[EDIT] Before the ignorant start flaming me for "indexes" check your dictionary. "Indexes" is a perfectly viable alternative to "indices". It's happened before. [/EDIT]
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
I might be completely wrong (usually am) but i think you need to set the ans[x] = to an instance of the answer class before you can do anything with it. Because it has not been instantiated yet you get your Null Reference Exception.
Try initializing each element in the array to a blank Answer class.
This sounds right to me but without actually trying it i don;t know.
Let me know how you get on,
Cheers
Kev Pearman MCP
|
|
|
|