c# - my class gives no value back that I can use -
this how try print worthwhile site using class, when try write class not find @ all.
i can not find worth return worthwhile user.
the problem can not find @ class.
my class:
public class abonnementsid { public int indhold { get; set; } } public abonnementsid hentabonnementsid() { abonnementsid abonnementsidreturn = new abonnementsid(); abonnementsidreturn.indhold = 0; sqlconnection conn1 = new sqlconnection(configurationmanager.connectionstrings["connectionstring"].tostring()); sqlcommand cmd1 = conn1.createcommand(); cmd1.connection = conn1; int brugerid = convert.toint32(httpcontext.current.session["id"]); cmd1.commandtext = @"select abonnementsid brugere id = @id"; cmd1.parameters.addwithvalue("@id", brugerid); conn1.open(); sqldatareader readerbrugera = cmd1.executereader(); if (readerbrugera.read()) { abonnementsidreturn.indhold = convert.toint32(readerbrugera["abonnementsid"]); } conn1.close(); return abonnementsidreturn; }
here how write class out when need content.
if (session["abonnementsid"] != null) { _subscriptionid = long.parse(session["abonnementsid"].tostring()); } else { //when need print class here _subscriptionid = abonnementsidreturn.indhold(); }
i'm totally shooting in dark here:
public static class abonnementsid { public static int getabonnementsid() { int abonnementsid; string connectionstring = configurationmanager.connectionstrings["connectionstring"].tostring(); using(var conn = new sqlconnection(connectionstring)) { int brugerid = convert.toint32(httpcontext.current.session["id"]); sqlcommand cmd1 = conn.createcommand(); cmd1.connection = conn; cmd1.commandtext = @"select abonnementsid brugere id = @id"; cmd1.parameters.addwithvalue("@id", brugerid); conn.open(); sqldatareader readerbrugera = cmd1.executereader(); if (readerbrugera.read()) abonnementsid = convert.toint32(readerbrugera["abonnementsid"]); conn.close(); } return abonnementsid; } }
you can call in code:
if (session["abonnementsid"] != null) { _subscriptionid = long.parse(session["abonnementsid"].tostring()); } else { //when need print class here _subscriptionid = abonnementsid.getabonnementsid(); }
Comments
Post a Comment