How can I save a variable from a database and use it in C#? -
i changing program , need because don't know c#. change things with:
strsql = "update materials set "; strsql = strsql + "dscr = 'concrete', "; strsql = strsql + "width=50 "; strsql = strsql + " id=385"; objcmd = new oledbcommand(strsql, db_def.conn); objcmd.executenonquery();
there case need find id, store , use again. use select
oledbcommand cmd = new oledbcommand("select id materials type=1", db_def.conn); oledbdatareader reader = cmd.executereader(); if (reader.hasrows) { reader.read(); var result = reader.getint32(0); } strsql = "update materials set "; strsql = strsql + "dscr = 'concrete', "; strsql = strsql + "width=50 "; strsql = strsql + " id=result"; objcmd = new oledbcommand(strsql, db_def.conn); objcmd.executenonquery();
but error:
no value given 1 or more required parameters.
you can try , tell me if works
oledbcommand cmd = new oledbcommand("select id materials type=1", db_def.conn); oledbdatareader reader = cmd.executereader(); int result=-1 ; if (reader.hasrows) { reader.read(); result = reader.getint32(0); } if (result != -1) { strsql = "update materials set "; strsql = strsql + "dscr = 'concrete', "; strsql = strsql + "width=50 "; strsql = strsql + " id="+result; objcmd = new oledbcommand(strsql, db_def.conn); objcmd.executenonquery(); }
Comments
Post a Comment