vb.net - Cannot update Data in mySQL database -
what want is, check first if id number exist, if exist updating process, problem is, not update. problem ?
sqlconn = new mysqlconnection sqlconn.connectionstring = "server=localhost;userid=root;password='';database=innovative" try sqlconn.open() query = "select full_name employee id='" & txt_id_number.text & "'" cmd = new mysqlcommand(query, sqlconn) reader = cmd.executereader if reader.hasrows = false msgbox("invalid id number please secure id number exist" & vbnewline & "take note:" & vbnewline & "you cannot update or change existing id number primary key employee, if want change it, better delete employee add again." & vbnewline & "other can change full name, age, contact , etc.", vbcritical) else reader.close() sqlconn.open() query1 = "update employee set full_name ='" & txt_fullname.text & "', employee_type='" & txt_employee_type.text & "', age='" & txt_age.text & "',sex='" & cb_sex.text & "', status='" & txt_status.text & "', contact ='" & txt_contact.text & "',e_mail='" & txt_email.text & "' id = '" & txt_id_number.text & "'" cmd = new mysqlcommand(query1, sqlconn) reader1 = cmd.executereader msgbox(txt_fullname.text & " updated", vbinformation) txt_age.text = "" txt_contact.text = "" txt_email.text = "" txt_employee_type.text = "" txt_fullname.text = "" txt_id_number.text = "" txt_status.text = "" cb_sex.text = "" add_employee() end if sqlconn.close() catch ex exception sqlconn.dispose() end try
imports mysql.data.mysqlclient public class form1 private sqlconn mysqlconnection private query, query1 string private cmd mysqlcommand private reader mysqldatareader private sub button1_click(sender object, e eventargs) handles button1.click sqlconn = new mysqlconnection sqlconn.connectionstring = "server=localhost;userid=root;password='';database=innovative" try sqlconn.open() query = "select full_name employee id='" & txt_id_number.text & "'" cmd = new mysqlcommand(query, sqlconn) reader = cmd.executereader if reader.hasrows = false msgbox("invalid id number please secure id number exist" & vbnewline & "take note:" & vbnewline & "you cannot update or change existing id number primary key employee, if want change it, better delete employee add again." & vbnewline & "other can change full name, age, contact , etc.", vbcritical) else query1 = "update employee set full_name = @txt_fullname, employee_type=txt_employee_type, age=@txt_age'" cmd = new mysqlcommand(query1, sqlconn) cmd.commandtype = commandtype.text cmd.parameters.add("@txt_fullname", sqldbtype.varchar, 255).value = txt_fullname.text cmd.parameters.add("@txt_employee_type", sqldbtype.varchar, 255).value = txt_employee_type.text cmd.parameters.add("@txt_age", sqldbtype.varchar, 255).value = txt_age.text cmd.parameters.add("") cmd.executenonquery() msgbox(txt_fullname.text & " updated", vbinformation) txt_age.text = "" txt_contact.text = "" txt_email.text = "" txt_employee_type.text = "" txt_fullname.text = "" txt_id_number.text = "" txt_status.text = "" cb_sex.text = "" add_employee() end if sqlconn.close() reader.close() catch ex exception sqlconn.dispose() end try end sub end class
Comments
Post a Comment