Click here to Skip to main content
15,899,632 members
Home / Discussions / C#
   

C#

 
AnswerRe: Set & Get in a C# Class Pin
Not Active15-Feb-07 4:07
mentorNot Active15-Feb-07 4:07 
GeneralRe: Set & Get in a C# Class Pin
Colin Angus Mackay15-Feb-07 4:13
Colin Angus Mackay15-Feb-07 4:13 
GeneralRe: Set & Get in a C# Class Pin
allan.gagnon15-Feb-07 4:32
allan.gagnon15-Feb-07 4:32 
GeneralRe: Set & Get in a C# Class Pin
Not Active15-Feb-07 4:33
mentorNot Active15-Feb-07 4:33 
AnswerRe: Set & Get in a C# Class Pin
Colin Angus Mackay15-Feb-07 4:12
Colin Angus Mackay15-Feb-07 4:12 
GeneralRe: Set & Get in a C# Class Pin
allan.gagnon15-Feb-07 4:26
allan.gagnon15-Feb-07 4:26 
GeneralRe: Set & Get in a C# Class Pin
allan.gagnon15-Feb-07 4:44
allan.gagnon15-Feb-07 4:44 
GeneralRe: Set & Get in a C# Class Pin
Colin Angus Mackay15-Feb-07 5:32
Colin Angus Mackay15-Feb-07 5:32 
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)
{
    // No match - user is not logged in
}
else
{
   // A match has been found - user can be logged in.
}


Does this help?


GeneralRe: Set & Get in a C# Class Pin
allan.gagnon16-Feb-07 3:19
allan.gagnon16-Feb-07 3:19 
Questionselecting image Pin
HexaDeveloper15-Feb-07 3:46
HexaDeveloper15-Feb-07 3:46 
QuestionHow can SqlDataReader implement IDisposable in .NET v1 when the Dispose method is private??!! Pin
cufc15-Feb-07 3:29
cufc15-Feb-07 3:29 
AnswerRe: How can SqlDataReader implement IDisposable in .NET v1 when the Dispose method is private??!! Pin
m@u15-Feb-07 3:45
m@u15-Feb-07 3:45 
GeneralRe: How can SqlDataReader implement IDisposable in .NET v1 when the Dispose method is private??!! Pin
cufc16-Feb-07 1:20
cufc16-Feb-07 1:20 
GeneralRe: How can SqlDataReader implement IDisposable in .NET v1 when the Dispose method is private??!! Pin
m@u16-Feb-07 2:26
m@u16-Feb-07 2:26 
QuestionI want to make a form as mirror for desktop Pin
waleed9915-Feb-07 3:22
waleed9915-Feb-07 3:22 
AnswerRe: I want to make a form as mirror for desktop Pin
Niiiissssshhhhhuuuuu15-Feb-07 3:33
Niiiissssshhhhhuuuuu15-Feb-07 3:33 
GeneralRe: I want to make a form as mirror for desktop Pin
waleed9915-Feb-07 5:10
waleed9915-Feb-07 5:10 
GeneralRe: I want to make a form as mirror for desktop Pin
Niiiissssshhhhhuuuuu15-Feb-07 17:47
Niiiissssshhhhhuuuuu15-Feb-07 17:47 
Questionweb based data analysis tool for stocks Pin
tota123415-Feb-07 2:59
tota123415-Feb-07 2:59 
AnswerRe: web based data analysis tool for stocks Pin
alex.almeida15-Feb-07 7:56
alex.almeida15-Feb-07 7:56 
GeneralRe: web based data analysis tool for stocks Pin
tota123415-Feb-07 8:20
tota123415-Feb-07 8:20 
GeneralRe: web based data analysis tool for stocks Pin
alex.almeida15-Feb-07 8:37
alex.almeida15-Feb-07 8:37 
GeneralRe: web based data analysis tool for stocks Pin
tota123415-Feb-07 9:08
tota123415-Feb-07 9:08 
GeneralRe: web based data analysis tool for stocks Pin
alex.almeida16-Feb-07 0:52
alex.almeida16-Feb-07 0:52 
GeneralRe: web based data analysis tool for stocks Pin
tota123420-Feb-07 0:53
tota123420-Feb-07 0:53 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.