asp.net - C# SqlDataReader No data exists for the row/column -
i've been away programming while i've got need it.
i have problem sql datareader using sql server compact edition 4.0 (vs2012 built-in).
string connstring = "data source=c:\\..(path here)..\\vacationsdb.sdf"; sqlceconnection conn = new sqlceconnection(connstring); string strsql = "select * vacation vacationno = @val"; using (sqlcecommand cmd = new sqlcecommand(strsql, conn)) { //read search value from text field cmd.parameters.addwithvalue("@val", vacationno_txt.text); conn.open(); sqlcedatareader reader = cmd.executereader(); fname_txt.text = reader.getstring(0); mname_txt.text = reader.getstring(1); /* * .. snip */ vacationno_txt.text = reader.getstring(11); conn.close(); }
i keep getting error: "invalidoperationexception unhandled. no data exists row/column." , error points @ fname_txt.text = reader.getstring(0);
but there data there because "submit" button it's code working , i've checked in database table itself.
any tips? thank you.
datareaders start out before first row.
to read first row, call read()
once.
if there no first row, read()
return false
.
Comments
Post a Comment