How to retrieve return row value from a SQL Server Compact database using C#.NET winform -


table columns:

rowid, username, password, administrator,  

my code:

sqlceconnection con = new sqlceconnection(@"data source=c:\visual studio 2010\projects\compactsql\compactsql\dbcompact.sdf;"); con.open();  sqlcecommand cmd = new sqlcecommand("select * dblogin username = '" + textbox1.text + "' , password = '" + textbox2.text + "'", con);  cmd.executenonquery();  int32 cnt = (int32)cmd.executescalar();  messagebox.show(cnt.tostring()); datatable dt = new datatable();  sqlcedataadapter da = new sqlcedataadapter(cmd); da.fill(dt);  foreach (datarowview dr in dt.rows)  {     // how column result based on sqlcecommand execute?  }  /* ex.: work on linq sql use "foreach"          gather results of column retrieved based on          query statement executed.          foreach(var r in row)          {             id = r.rowid;             user = r.username;             pass = r.password;             access = r.access;             logid = r.logid          } */ 

i use sql server compact database login form want when user login input username , password on text field query execute compare if user exist on compact db , when found return username, access, , logid in loop count of how many row record exist.

try this

foreach (datarow dr in dt.rows)  {     id = dr["rowid"].tostring();     user = dr["username"].tostring();;     pass = dr["password"].tostring();;     access = dr["access"].tostring();;     logid = dr["logid"].tostring(); } 

you may need convert values appropriate type id , logid looks int type.


Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -