c# - Must declare the scalar variable on @wachtwoord SQL -
i got error:
must declare scalar variable @wachtwoord
i tried solve using post: same error no luck far. bit lost. want generate code @wachtwoord
(password). want count rows in database. use count statement, in statement update
statement update every row in database own generated password.
if guys have advise or solution problem great!
this code:
public partial class form1 : form { string cn = "data source=pc-wesley;initial catalog=projectvoteordie;integrated security=true"; string cm1 = "update test set wachtwoord = @wachtwoord id = @id"; string cm2 = "select count(*) test;"; public form1() { initializecomponent(); } private void btnklik_click(object sender, eventargs e) { var chars = "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz0123456789"; var random = new random(); //random code gen var result = new string( enumerable.repeat(chars, 8) .select(s => s[random.next(s.length)]) .toarray()); sqlconnection scn = new sqlconnection(cn); sqlcommand scm1 = new sqlcommand(cm1, scn); sqlcommand scm2 = new sqlcommand(cm2, scn); try { scn.open(); int rows = convert.toint32(scm2.executescalar()); scm2.parameters.clear(); (int = 1; <= rows; i++) { scm1.parameters.addwithvalue("@wachtwoord", result); scm1.parameters.addwithvalue("@id", i); scm1.parameters.clear(); scm1.executenonquery(); } } catch (exception se) //got error on { lblrandom.text = convert.tostring(se); } { scn.close(); } }
Comments
Post a Comment