how to set record by update query sql vb.net -


i have table , want set value if cell=null set record textbox . here table

-------------------- col1| col2| note 1       2    aaa 5       5    (*)  set record here if cell null 42     14 47     55    ------------------ 

here code , problem query write every cell null , want write next cell before not null

con.open() query = " update firealarm set note=@note note null" dim command sqlcommand = new sqlcommand(query, con) command.parameters.add(new sqlparameter("@note", sqldbtype.nvarchar)) command.parameters("@note").value = notebox.text.tostring command.executenonquery() con.close() 

first, let's fix immediate problem: in sql null not equal anything, including other nulls, note<>null true rows. address problem, sql has special operators is null , is not null. using where note not null fix problem.

a bigger problem remains, though: program vulnerable sql injection attack. fix problem in visual basic see this q&a.

edit: (in response edit of question)

i want write next cell before not null

the "next cell" implies order of cells in table. since table rows should treated unordered collection, let's assume order col1, way data ordered in example.

the query condition becomes bigger this:

update f set f.note=@note firealarm f note null   , not exist (     select * firealarm ff ff.col1 < f.col1 , ff.note null   ) 

the new where condition says update needs done on cell lowest col1 , null value in note column.


Comments

Popular posts from this blog

twig - Using Twigbridge in a Laravel 5.1 Package -

jdbc - Not able to establish database connection in eclipse -

firemonkey - How do I make a beep sound in Android using Delphi and the API? -