Error in Insert into statement in vb.net queries -


i tried match query earlier posts not able resolve problem.

i have table user_master importing permission_id , zone_id other tables key. date in short format.

 cmd.commandtext = "insert user_master(uname, password, creation_date, creation_time, permission_id, zone_id)" & "values('" & txtuname.text & "','" & txtupass.password & "','" & date_gl & "','" & time_gl & "','" & _user_perm & "','" & _zone_id & "')" 

cmd.executenonquery()

the primary key autonumber, creation_date/time executed in other query , permission_id , zone_id numbers. other fields texts. tried several permutations , combinations altering query (removing quotes etc.) field count same. please let me know parameter executing wrong?

same case for,

cmd.commandtext = "update user_master set uname = " & """" & txtuname.text & """" & _                         " , password = " & """" & txtupass.password & """" & _                         " , creation_date = " & """" & date_gl & """" & _                         " , creation_time = " & """" & time_gl & """" & _                         " , permission_id = " & _user_perm & _                         " , zone_id = " & _zone_id & _                         " id = " & _usr_id_temp                     cmd.executenonquery() 

i hope right help.

thank you, abhimoh

i suppose previous answer using ms-access , oledb update database.
if case password reserved keyword , need encapsulate square bracket. use parameterized query avoid parsing problems of text, decimals , dates , of course prevent sql injections

cmd.commandtext = "update user_master set uname = ?" & _                    " , [password] = ?" & _                    " , creation_date = ?" & _                    " , creation_time = ?" & _                    " , permission_id = ?" & _                    " , zone_id = ? & _                    " id = ?" cmd.parameters.addwithvalue("@p1",txtuname.text) cmd.parameters.addwithvalue("@p2",txtupass.password) cmd.parameters.addwithvalue("@p3",date_gl) cmd.parameters.addwithvalue("@p4",time_gl) cmd.parameters.addwithvalue("@p5",_user_perm) cmd.parameters.addwithvalue("@p6",_zone_id) cmd.parameters.addwithvalue("@p7",_usr_id_temp) cmd.executenonquery() 

Comments

Popular posts from this blog

java - Run spring boot application error: Cannot instantiate interface org.springframework.context.ApplicationListener -

reactjs - React router and this.props.children - how to pass state to this.props.children -

Excel VBA "Microsoft Windows Common Controls 6.0 (SP6)" Location Changes -