c# - SQL Server weirdest error ever -


the c# code:

sqlconnection c;  string str = "data source =(localdb)\\mssqllocaldb;"; str += "attachdbfilename=|datadirectory|\\dinodata.mdf;"; str += "integrated security= true";  c = new sqlconnection(str);  if (session["connect"] != null) {     if ((bool)session["connect"])     {         logdiv.visible = false;         usernamec.innerhtml = (string)session["curentuserid"];         connected.visible = true;          sqlcommand exp = new sqlcommand("select xp from[user] username = @username", c);         exp.parameters.addwithvalue("@username", (string)session["curentuserid"]);          c.open();         session["exp"] = exp.executereader();         c.close();          int b = (int)session["exp"] / 2;         string = b + "px";         xp.style.add("width", ((string)session["exp"])+"%");     }     else     {         connected.visible = false;         logdiv.visible = true;     } } 

the error:

an exception of type 'system.invalidcastexception' occurred in app_web_ump4h2pq.dll not handled in user code

additional information: specified cast not valid.

 sqlconnection c;         string str = "data source =(localdb)\\mssqllocaldb;";         str += "attachdbfilename=|datadirectory|\\dinodata.mdf;";         str += "integrated security= true";         c = new sqlconnection(str);         if (session["conect"] != null)         {             if ((bool)session["conect"])             {                 logdiv.visible = false;                 usernamec.innerhtml = (string)session["curentuserid"];                 connected.visible = true;                 sqlcommand exp = new sqlcommand("select xp from[user] username = @username", c);                 exp.parameters.addwithvalue("@username", (string)session["curentuserid"]);                 c.open();                 session["exp"] = exp.executescalar();                 c.close();                 int b = (int)session["exp"] / 2;                 string = b + "%";                 xp.style.add("width", a);             }             else             {                 connected.visible = false;                 logdiv.visible = true;             } 

fixed :)


Comments

Popular posts from this blog

ios - RestKit 0.20 — CoreData: error: Failed to call designated initializer on NSManagedObject class (again) -

laravel - PDOException in Connector.php line 55: SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES) -

java - Digest auth with Spring Security using javaconfig -