Login Form - C# 2005 Express Edition

jcrcarmo

Freshman
Joined
Dec 14, 2005
Messages
32
Hi everybody,

The following code runs fine util the commented lines. The debugger halts and sends me a message saying that "custView is a variable and is being used as a method". Can anyone shed some light on this? Thank you very much.

Best regards,

JC :)


--------------------------------------------------------------------------


private void btnLogin_Click(object sender, EventArgs e)
{
System.Data.DataView custViewLogin = new System.Data.DataView(SASCRDataSet.tabUsers, "", "Login", System.Data.DataViewRowState.CurrentRows);
System.Data.DataView custViewPassword = new System.Data.DataView(SASCRDataSet.tabUsers,"", "Password", System.Data.DataViewRowState.CurrentRows);

int rowIndexLogin = custViewLogin.Find(this.txtUserName.Text);
int rowIndexPassword = custViewPassword.Find(this.txtPassword.Text);

if (rowIndexLogin == -1 || rowIndexPassword == -1)
{
MessageBox.Show("Usuário ou Senha inválida. \r" + "Por favor tente de novo. ", "Acesso negado ...", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
this.txtPassword.Focus();
this.txtPassword.Text = "";
CTM = CTM + 1;

if (CTM == TRYMAX)
{
MessageBox.Show("Você usou o nº máximo de tentativas \r" + " de login e está sendo desconectado \r" + " por motivos de segurança! ", "Acesso bloqueado ...", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
Application.Exit();
}
}
else
{
//---------------- This is where the problems starts---------------
this.UserRealName.Text = custViewLogin(rowIndexLogin)("UserRealName").ToString();
this.AccessRights.Text = custViewLogin(rowIndexLogin)("AccessRights").ToString();
//---------------- This is where the problems finishes---------------

Form frmMain = new frmMain();
frmMain.Show();
this.Hide();
}
}
 
Did you learn VB before C#? Try swapping the ( ) with [ ]:
C#:
this.UserRealName.Text = custViewLogin[rowIndexLogin]["UserRealName"].ToString();
this.AccessRights.Text = custViewLogin[rowIndexLogin]["AccessRights"].ToString();
( ) is used for indexers in VB but [ ] is the indexer in C#, similiar to C++.
 
Hi mskeel,

Yes, I did learn VB way before I started learning C#. How did you guess that? hehehe. Anyway, I'm getting to love C# more and more for it's a more robust language and seems to be processed a lot faster by my machine.

Thank you so much for your reply. I can't believe the solution was so simple... Just amazing! Now the code works just fine. Thanks a million!

Bye for now,

JC :)
 
Back
Top