c# - How can I convert Dataset column value to an integer -


public dataset ds = new dataset(); public sqldataadapter adapter = new sqldataadapter();  public int authenticateduserage(string user_name) {     string sql = "select username, age tbldataprog (username ='" +   user_name  + "')";     ds = getdataset(sql);     int = int.parse(ds.tables[0].rows[0]["age"].tostring());     return help;     }  public dataset getdataset(string sql) {     sqlconnection connection = new sqlconnection(connstr());     sqlcommand cmd = new sqlcommand();     cmd.commandtext = sql;     cmd.connection = connection;     adapter = new sqldataadapter(cmd);     connection.open();     adapter.fill(ds);     connection.close();     return ds; }      public string connstr() {     return @"data source=.\sqlexpress;attachdbfilename='g:\עבודת גמר תכנות\v5\חדש תיקיה 1\v4\app_data\sitedb.mdf';integrated security=true;user instance=true"; } 

i need check value returned authenticateduserage number less 17 write hello teenager else write hello adult.

the problem think line doesn't return value:
int = int.parse(ds.tables[0].rows[0]["age"].tostring());
throws error:

input string not in correct format

this not answer, not clear in comment.

break line up:

int = int.parse(ds.tables[0].rows[0]["age"].tostring()); 

into:

//set breakpoint on next line string temp = ds.tables[0].rows[0]["age"].tostring();  //take 1 step (f10) on break , hover on temp //or use watch.  value of temp? int = int.parse(temp); 

Comments

Popular posts from this blog

how to proxy from https to http with lighttpd -

android - Automated my builds -

python - Flask migration error -