|
No didn't work for me either.
Be sure your workstation is:
a. Windows XP Pro (sp 2)
b. VS2005 .NET
c. .NET 2.0
So far I'm using the GetHostByAddress method, although I recieve a 'yellow' warning during the compile, it does still compile and not halt in error like the Resolve method does now since .NET 2.0. The program will open and run as usual. However, I would like a flawless code like before the .Resolve obsolecsence.
string hostname = System.Net.Dns.GetHostByAddress(IPAddress.Parse(entry)).HostName;
|
|
|
|
|
Is there a way to designate a property as only being usable say, during serialization? For example, I need a setter that sets the string value during deserialization, but under no other condition should this setter ever be used.
I really miss the "friend" feature of C++.
[edit]I'm using C# 2.0, if that helps.[/edit]
Marc
Pensieve
-- modified at 14:00 Saturday 11th February, 2006
|
|
|
|
|
Well, I came across a way of doing this by accident sometime ago while I was exploring something else. However, I can't remember exactly what I did now! Some combination of attributes and reflection.
Kevin
|
|
|
|
|
If you are using binary serialization, the visibility of the property doesn't matter, because the serializer uses the (private) fields.
Xml serialization is different. You could use the OnDeserialized attribute to execute a method whoch sets a boolean flag. In the setter, check the flag and throw an exception.
|
|
|
|
|
In VC++ was the #pragma warning directive, for example:
#pragma warning( push ) // Store the current warning level for all warnings
#pragma warning( disable : 4705 )
#pragma warning( disable : 4706 )
#pragma warning( disable : 4707 )
// Some code goes here...
#pragma warning( pop ) // Pops the last warning level
Is there any directive in C# that do the same job?
Thanx in advanced!
|
|
|
|
|
Project Properties -> Configuration Properties -> Suppress Specific Warnings
Kevin
|
|
|
|
|
THANX kevin, however - this setting is global to the project, to supress specific warning in specific portion of code and the restore it - now i have learned (by the other replyers of this post) that it is possible in .net 2.0 framework.
Regards, ilan
|
|
|
|
|
Cool. I didn't know that.
Kevin
|
|
|
|
|
I believe you can only do this using v2.0 of the .Net Framework
#pragma warning disable 0169, 0414
Regards
Wayne Phipps
____________
Time is the greatest teacher... unfortunately, it kills all of its students
View my Blog
|
|
|
|
|
This is documented right here[^]. This is NOT SUPPORTED in C# 1.0 and 1.1. This is a new capability introduced in C# 2.0.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
|
i am using the following function to close some open forms with tag "NOTMAIN" in my application.
private void CloseOldForms()
{
FormCollection frmColl = Application.OpenForms;
foreach (Form tempFrm in frmColl)
{
string tempFrmTxt = tempFrm.Tag.ToString();
if (tempFrmTxt.Equals("NOTMAIN"))
{
tempFrm.Close();
}
}
}
But after looping one time in foreach loop,the application stops with an exception i.e enumeration was modified operation may not execute.
So can anybody tell how can i do the task
|
|
|
|
|
The call to tempFrm.Close() modifies the Application.OpenForms property. Try this:
private void CloseOldForms()
{
ArrayList frmColl = new ArrayList();
frmColl.AddRange (Application.OpenForms);
foreach (Form tempFrm in frmColl as Form) {
string tempFrmTxt = tempFrm.Tag.ToString();
if (tempFrmTxt.Equals ("NOTMAIN")) {
tempFrm.Close();
}
}
}
/ravi
My new year's resolution: 2048 x 1536
Home | Music | Articles | Freeware | Trips
ravib(at)ravib(dot)com
|
|
|
|
|
Try this instead:
private void CloseOldForms()
{
FormCollection frmColl = Application.OpenForms;
foreach ( int i = 0; i < frmColl.Count; ++i )
{
Form tempFrm = frmColl[i];
string tempFrmTxt = tempFrm.Tag.ToString();
if (tempFrmTxt.Equals("NOTMAIN"))
{
tempFrm.Close();
}
}
}
I'm not absolutely sure of this, but I think that when you call Close on your form, it is attempting to remove the form object from the form collection automatically which is what causes this error since you are at that point in effect trying to alter the contents of the collection over which you are iterating.
Hope that helps.
-Matt
------------------------------------------
The 3 great virtues of a programmer:
Laziness, Impatience, and Hubris.
--Larry Wall
|
|
|
|
|
perlmunger wrote: foreach ( int i = 0; i < frmColl.Count; ++i )
This WILL cause an IndexOutOfRange exception. The solution is very easy, but not so obivous:
foreach ( int i = frmColl.Count; i >= 0; i-- )
Run the the loop in the other direction! Start at the end and work your way back to the front...
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
-- modified at 14:47 Saturday 11th February, 2006
|
|
|
|
|
Good point.
Thanks.
-Matt
------------------------------------------
The 3 great virtues of a programmer:
Laziness, Impatience, and Hubris.
--Larry Wall
|
|
|
|
|
perlmunger wrote: foreach ( int i = 0; i < frmColl.Count; ++i )
This may cause index out of rnage exception. I think while (frmColl.Count>0) woulld be a safer alternative. In which case, you will also have to replace the following line with
Form tempFrm = frmColl[0];
- Malhar
|
|
|
|
|
That won't work because there is the potential that not all forms are going to be closed and removed from the collection, therefore this would result in an infinite loop - which is less than desirable.
ColinMackay.net
"Man who stand on hill with mouth open will wait long time for roast duck to drop in." -- Confucius
"If a man empties his purse into his head, no man can take it away from him, for an investment in knowledge pays the best interest." -- Joseph E. O'Donnell
|
|
|
|
|
You may be right. I hadn't seen this property "OpenForms" of Application class. I am assuming it is newly introduced in 2.0,
- Malhar
|
|
|
|
|
It was nothing to do with that. It was to do with this:
if (tempFrmTxt.Equals("NOTMAIN"))
{
tempFrm.Close();
} That introduces the aspect that no all forms will be closed. Which means that the while loop becomes infinite if as much as one form is to stay open.
ColinMackay.net
"Man who stand on hill with mouth open will wait long time for roast duck to drop in." -- Confucius
"If a man empties his purse into his head, no man can take it away from him, for an investment in knowledge pays the best interest." -- Joseph E. O'Donnell
|
|
|
|
|
You're 100% correct. I had overlooked that little piece of detail.
- Malhar
|
|
|
|
|
thank you all for taking some time to reply.i finally managed to overcome the problem with ur suggestion.the following code now works fine.
private void CloseOldForms()
{
FormCollection frmColl = Application.OpenForms;
for (Int32 index = 0; index < frmColl.Count; index++)
{
string tempFrmTxt = frmColl[index].Tag.ToString();
if (frmColl[index] != this)
{
if (frmColl[index].Text.Equals("NODEINFO"))
{
frmColl[index].Close();
index--;
}
}
if (tempFrmTxt.Equals("NOTMAIN"))
{
frmColl[index].Close();
index--;
}
}
}
|
|
|
|
|
the problem is in my webservice, but this is in C#, and the problem is more C# related.
the code below is the code i use, it always return false through the Catch, the Catch returns an error found in here[^] (the blue boxes are the absolute paths, you don't need them).
the problem i can't figure out, is why?
if someone can help me i would be very thankful.
yours, NaNg.
[WebMethod]<br />
public bool AddProject(string ProjName, string ProjID)<br />
{<br />
try<br />
{<br />
objCon.Open();<br />
DataSet ds = new DataSet();<br />
objDA = new OleDbDataAdapter(string.Format("Select Count([SID]) from tblProjects Where SPorjID = '{0}' And SProjName = '{1}'", ProjID, ProjName), objCon);<br />
123 -> objDA.Fill(ds, "tblProjects");<br />
if ((int)ds.Tables[0].Rows[0][0] == 0)<br />
{<br />
objCmd = new OleDbCommand(string.Format("Insert into tblProjects(SProjID, SProjName) Values('{0}', '{1}')", ProjID, ProjName), objCon);<br />
objCmd.ExecuteNonQuery();<br />
return true;<br />
}<br />
else<br />
return false;<br />
}<br />
catch (Exception exp)<br />
{<br />
return false;<br />
}<br />
finally<br />
{<br />
objCon.Close();<br />
}<br />
}
|
|
|
|
|
You either need to set the insert command's command text or you need to use parameters. Change your code to do this instead:
string selectCommand = "SELECT COUNT...";
objDA = new OleDbDataAdapter( selectCommand, connection );
objDA.InsertCommand.CommandText = string.Format("Insert into tblProjects(SProjID, SProjName) Values('{0}', '{1}')", ProjID, ProjName);
objDA.InsertCommand.ExecuteNonQuery();
Alternatively, you can use parameters like this:
string selectCommand = "SELECT COUNT...";
objDA = new OleDbDataAdapter( selectCommand, connection );
objDA.InsertCommand = new OleDbCommand( "Insert into tblProjects(SProjID, SProjName) Values( ?, ?)", connection );
objDA.InsertCommand.Parameters.Add( "@SProjID", OleDbType.VarChar, 30, "SProjID" ).Value = ProjID;
objDA.InsertCommand.Parameters.Add( "@SProjName", OleDbType.VarChar, 30, "SProjName" ).Value = ProjName;
objDA.InsertCommand.ExecuteNonQuery();
Hope that helps.
-Matt
------------------------------------------
The 3 great virtues of a programmer:
Laziness, Impatience, and Hubris.
--Larry Wall
|
|
|
|
|
hmmm... =\ both of them give me the same exception as before, nothing works and i don't know why =\
and i want to focus you, the problem is not in the insert command, but in the select command.
string.Format("Select Count([SID]) from tblProjects Where SPorjID = '{0}' And SProjName = '{1}'", ProjID, ProjName);
|
|
|
|