1

The error line:

Source Error:

Line 37:         while (rdr.Read()==true)
Line 38:         {
Line 39:             if (TextBoxUserName.Text == (string)rdr["CUserName"]) 
Line 40:             {
Line 41:                 ClientScript.RegisterStartupScript(csType,"Error",scriptErrorUserId);

It pops up when I tried to register an account.

I use microsoft access as database.

Database - CUserName Session - sUserName and there's @eUserName

any idea guys?

Marcus Moo
  • 196
  • 1
  • 2
  • 20

2 Answers2

3

You need to check if rdr["CUserName"] equals to System.DBNull.Value first before converting it to string. Change this:

if (TextBoxUserName.Text == (string)rdr["CUserName"])

to this:

string userName = rdr["CUserName"] != System.DBNull.Value ? (string)rdr["CUserName"] : string.Empty;
if (TextBoxUserName.Text == userName)
ekad
  • 14,436
  • 26
  • 44
  • 46
  • Yours make sense but the other guy answer solved it. I didnt tried yours because I think its not necessary to != system.dbnull.value uh ? – Marcus Moo Jan 19 '14 at 12:52
  • 1
    For string data type, you may not need to check `!= System.DBNull.Value`, but you will need it for other data types, i.e decimal or integer. – ekad Jan 19 '14 at 12:55
3

Replace this

if (TextBoxUserName.Text == (string)rdr["CUserName"])

with

if (TextBoxUserName.Text == rdr["CUserName"].ToString())
prograshid
  • 876
  • 3
  • 12
  • 32