|
The Select() calls were killing me.
It was actually faster to just select everything, sorted by ItemId and iterate through the two arrays using a while-loop nested within a for-loop, bailing out of the while whenever I got a match or when the Id I was comparing was greater than the current one in the while loop.
Ended up cutting down the processing time to maybe a second or so. Should have realized how inefficient the original algorithm was.
|
|
|
|
|
I am having a lot of trouble finding sample code on the internet showing how to browse for a folder/directory through the propertygrid control.
I would like a user to be able to select a folder as backup directory for a project using the PropertyGrid control instead of using a standard windows form UI.
Currently my code looks like this:
<br />
using System.Windows.Forms.Design;<br />
using System.Drawing.Design;<br />
<br />
[global::System.Configuration.UserScopedSettingAttribute()]<br />
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]<br />
[EditorAttribute(typeof(FileNamEditor), typeof( UITypeEditor ))]<br />
[CategoryAttribute("Backup Directories")]<br />
[DescriptionAttribute("Default backup directory")]<br />
<br />
public string BackupDirectory <br />
{<br />
get <br />
{<br />
return _backupDirectory;<br />
}<br />
set <br />
{<br />
_backupDirectory = value;<br />
}<br />
}<br />
|
|
|
|
|
hi
change this line of code
[EditorAttribute(typeof(FileNamEditor), typeof( UITypeEditor ))]
with
[EditorAttribute(typeof(FolderNamEditor), typeof( UITypeEditor ))]
regards
|
|
|
|
|
Thank you for the quick reply, however, that is not working either. Visual Studio keeps giving me a compile error that I am missing a reference or using directive in regards to "FileNameEditor" or "FolderNameEditor". I just can't get it to work.
|
|
|
|
|
I solved the problem. You have to add a reference using the "add reference" dialog box to System.Design, then it works. If you don't make this reference then it will not work.
|
|
|
|
|
I want to make a Login class that I pass info from a text box in to a set variable in the class and then use a get variable to test if my login was successfull. Is this possible?
Newbie at C# but a big wannabe
Allan F. Gagnon
|
|
|
|
|
Yes
only two letters away from being an asset
|
|
|
|
|
What is a "set variable"? What is a "get variable"?
|
|
|
|
|
This is my question!!
Allan F. Gagnon
|
|
|
|
|
Guess I was assuming he meant set/get, but you never know around here.
only two letters away from being an asset
|
|
|
|
|
allan.gagnon wrote: I want to make a Login class that I pass info from a text box in to a set variable in the class and then use a get variable to test if my login was successfull. Is this possible?
I think there is some confusion about various terms because to me your request didn't make a lot of sense.
A class can have properties. A property can have a getter and/or setter and it could look like this:
class MyClass
{
private string someField;
public string SomeProperty
{
get
{
return this.someField;
}
set
{
this.someField = value;
}
}
}
As you can see the getter and setter refer to the same member variable (field). Or it can do other work to simulate similar functionality. Essentially a getter and setter are special methods that C# dresses up in syntactic sugar to make it look like a variable.
If you were to make a Login class, you might have a method that takes a user name and password. You can then use a property to tell the outside world whether the Login was successful.
class Login
{
private bool isLoggedIn;
public void AuthenticateUser(string userName, string password)
{
}
public bool IsLoggedIn
{
get
{
return this.isLoggedIn;
}
}
}
Does this help? Or does it help you form a better idea so that you can rephrase your question?
|
|
|
|
|
Great
Thank You!!
Allan F. Gagnon
|
|
|
|
|
Ok Thank you for the help so far this time I will try to explain the question better. I guess I am a newbie at c# and a newbie at asking questions about c#.
Here is question number 2:
I have wrote this code
public static void Login(String LoginBox)
{
string strConn, strSQL;
bool LoginSucceeded;
strConn = @"Data Source=.\SQLEXPRESS;AttachDbFilename=C:\Documents and Settings\admin\My Documents\Visual Studio 2005\Projects\GasCabinetSimulator\GasCabinetSimulator\GasCabinet.mdf;Integrated Security=True;User Instance=True";
strSQL = "SELECT UserID, PassWord, IsLoggedIn FROM tblLogin";
using (SqlConnection cn = new SqlConnection(strConn))
{
try
{
cn.Open();
}
catch (SqlException ex)
{
MessageBox.Show("Connect Attempt Failed");
MessageBox.Show(ex.Message);
return;
}
using (SqlCommand cmd = new SqlCommand(strSQL, cn))
{
try
{
using (SqlDataReader rdr = cmd.ExecuteReader())
{
while (rdr.Read())
if (LoginBox == rdr["PassWord"].ToString())
{
MessageBox.Show("Login successful","Login Success",
MessageBoxButtons.OK,MessageBoxIcon.Information);
MessageBox.Show(rdr["IsLoggedIn"].ToString());
rdr["IsLoggedIn"] = true;
}
rdr.Close();
}
}
catch (SqlException ex)
{
MessageBox.Show("Query failed");
MessageBox.Show(ex.Message);
return;
}
}
cn.Close();
However I am getting this error message when I build my project:
Error 1 Property or indexer 'System.Data.Common.DbDataReader.this[string]' cannot be assigned to -- it is read only C:\Documents and Settings\admin\My Documents\Visual Studio 2005\Projects\GasCabinetSimulator\GasCabinetSimulator\ClassLogin.cs 46 37 GasCabinetSimulator
This line is the error: rdr["IsLoggedIn"] = true;
Where am i going wrong?
Thank you again for all your help!!
Allan F. Gagnon
|
|
|
|
|
allan.gagnon wrote: However I am getting this error message when I build my project:
Error 1 Property or indexer 'System.Data.Common.DbDataReader.this[string]' cannot be assigned to -- it is read only C:\Documents and Settings\admin\My Documents\Visual Studio 2005\Projects\GasCabinetSimulator\GasCabinetSimulator\ClassLogin.cs 46 37 GasCabinetSimulator
This line is the error: rdr["IsLoggedIn"] = true;
The clue is in the name. You have a data reader. You cannot use it to write values to the database.
In order to update the database you need to issue a separate SQL command.
UPDATE tblLogin SET IsLoggedIn = 1 WHERE UserID = ????
You may wish to rethink your logic somewhat. Because you are not matching a user ID to a password. As soon as someone passes any valid password for any account (it doesn't matter which) they are permitted access. Who is accessing in reality and which account is being used is anyone's guess.
A Security tip: Don't let passwords escape from the database. The less you pass password data around the safer your system is. Consider:
SELECT COUNT(*) FROM tblLogin WHERE UserID = @userID AND Password = @password
And you can use ExecuteScalar to get a single value back. 0 = no match, 1 = match, any other value means that the data is invalid.
Also, I've used parameters here: @userID and @password
You use the Parameters collection of the SqlCommand to pass them in.
SqlCommand cmd = new SqlCommand();
cmd.CommandText = "SELECT COUNT(*) FROM tblLogin "+
"WHERE UserID = @userID AND Password = @password";
cmd.Connection = cn;
cmd.Parameters.Add("@userId", theUserId);
cmd.Parameters.Add("@password", thePassword);
int matches = (int)cmd.ExecuteScalar();
if (matches == 0)
{
}
else
{
}
Does this help?
|
|
|
|
|
This is completely awesome I have been trying to figure something like this out for about two weeks in books training videos and all with no luck!!! This is a great answer and I completely understand what your point is. Thank You very much.
This website is the greatest!!!
;P
Allan F. Gagnon
|
|
|
|
|
hi all,
how can i make an aura on image on the stage
Generator
|
|
|
|
|
SqlDataReader implements IDisposable in .NET 1.1, yet its Dispose method is private. How can this be? If I create an interface with a single member and try to implement it as private, it obviously won't compile!
This isn't causing me a huge problem, but it doesn't make sense and I'd like to know why.
Note that, in .NET 2, SqlDataReader inherits from DbDataReader, which has a public Dispose method.
David.
|
|
|
|
|
Hi..
No it's not private.
You can Implement an Interface in 2 ways.
First:
<br />
public class Blah:IDisposable<br />
{<br />
public void Dispose()<br />
{<br />
}<br />
}<br />
in This case you can say:
<br />
myBlahObject.Dispose();<br />
But, when you Implement it that way:
<br />
public class Blah:IDisposable<br />
{<br />
void IDisposable.Dispose()<br />
{<br />
}<br />
}<br />
<br />
myBlahObject.Dispose();<br />
will not work. but if you say:
<br />
(myBlahObject as IDisposable).Dispose();<br />
it works fine
hope this helps
greets
m@u
|
|
|
|
|
Thanks for the swift reponse m@u.
I used Lutz Roeder's excellent .NET Reflector (http://www.aisto.com/roeder/dotnet/) to query SqlDataReader in the 1.1 System.Data.dll, which gives the following result when viewing the Dispose method: -
private void Dispose(bool disposing);
This is why I stated that the Dispose method is private. (If I use Reflector to query an assembly with Dispose implemented as 'void IDisposable.Dispose();', it doesn't show
the method as being private).
Strange, isn't it?
Regards,
David.
|
|
|
|
|
ok well that's now something completly different
the Dispose(bool disposing) which is normally marked as protected virtual, is used, because you can not inherit interface Implementations.
if you look at the IDisposable Interface, you see, that the Dispose Method doesn't take any Parameters (Dispose()
now let's say you have an abstract class called myAbstractClass and you want to implement the IDisposable Interface on it. so your object looks like
<br />
public abstract class myAbstractClass:IDisposable<br />
{<br />
public abstract void Blah();<br />
void IDisposable.Dispose()<br />
{<br />
}<br />
}<br />
and now you want to implement a class, that extends this abstract class. so you make a new class called myImplementedClass
let's say, you have some variables in myImplementedClass , that you need to clean up when the object dies.
so you do:
<br />
public class myImplementedClass:myAbstractClass<br />
{<br />
private ClassThatNeedsToBeCleanedUpOnDispose foo;<br />
public override void Blah()<br />
{<br />
}<br />
public override void Dispose()
{<br />
}<br />
}<br />
as you see, this code will not work, because you can not override an Interface - Implementation.
so you have to modify the code of your base class. and that's where Dispose(bool disposing) comes in. because the new Code of your myAbstractClass will look like this:
<br />
public abstract class MyAbstractClass:IDisposable<br />
{<br />
public abstract void Blah();<br />
void IDisposable.Dispose()<br />
{<br />
Dispose(true);<br />
}<br />
protected virtual void Dispose(bool Disposing)<br />
{<br />
}<br />
}<br />
and now your new myImplementedClass looks like this:
<br />
public class myImplementedClass:myAbstractClass<br />
{<br />
private ClassThatNeedsToBeCleanedUpOnDispose foo;<br />
public override void Blah()<br />
{<br />
}<br />
protected override void Dispose(bool Disposing)<br />
{<br />
if (Disposing)<br />
{<br />
base.Dispose(Disposing);<br />
}<br />
}<br />
}<br />
<br />
now every class, that derives from your basic class or from a class that is derived from your basic class can implement Dispose(bool Disposing)
now you can say somewhere in your code
<br />
myAbstractClass blah = new derivedfromthederivedClassFrommyAbstractClass();<br />
(blah as IDisposable).Dispose();<br />
and every class in the inerit-chain of the derivedfromthederivedClassFrommyAbstractClass will dispose correctly because it has implemented Dispose(bool Disposing)
do you see now what Dispose(bool Disposing) is for?
i can't exactly tell you why reflector shows that as private, because that doesn't make sense, but normally, if you implement it as protected it's because of this here..
greets
m@u
|
|
|
|
|
Please I want app to make a form as a Monitor for my computer to show on the Form ,
Can any one give my the name of this program ,
|
|
|
|
|
Hello,
I was wondering if i am getting you correctly ..
you want the backgound of your form as desktop or what ???
Please clear the question
nishu
|
|
|
|
|
I am sorry , I want
1- 2 froms
2- the first one will appear the desktop , adn you know in the desktop my computer,documents like this .
3- i will open my computer through the first form ,this action will appear on the form2
.
if you dont understand my question
i can write it in another form.
thank you very much
|
|
|
|
|
that would be better..
nishu
|
|
|
|
|
our application would need:
1.import data(stock prices) from websites into a database(excel sheets)
2.interfacing excel sheets with the asp application
3.performing manipulations on the data and draw corresponding graphs(line,bar,..)
4.make the application accessible on a network
are asp.net and C# apt for the application?
can someone please help us with relevant code?
regards
ps:please reply asap
besides our email add are:
funwithsiddartha@gmail.com
lovelyritesh_in@yahoo.com
shobhit.samaria@gmail.com
abhinavsharma0507@gmail.com
|
|
|
|