c# - Verifing if text already exists -
i have sql table saves word , need check if word exists , so, should message saying word exists. possible? if how should it? leave down below myccode add word sql, if need else provide without problem.
string conn = configurationmanager.connectionstrings["test"].connectionstring; using (sqlconnection sqlconn = new sqlconnection(conn)) { sqlconn.open(); string sqlquery = @"insert testetiposdestados(cdu_estados) values(@estados)"; sqlcommand sqlcm = new sqlcommand(); sqlcm.connection = sqlconn; sqlcm.commandtext = sqlquery; sqlcm.commandtype = commandtype.text; sqlcm.parameters.addwithvalue("@estados", textbox1.text); sqlcm.executenonquery(); sqlconn.close(); }
i'm using c#
you can use if not exist
statment
if not exists (select * testetiposdestados cdu_estados = @estados) begin insert testetiposdestados(cdu_estados) values(@estados) end
your query become:
string sqlquery = @"if not exists(select * testetiposdestados cdu_estados = @estados) begin insert testetiposdestados(cdu_estados) values (@estados) end";
if inserted means not present in table already.
Comments
Post a Comment