Click here to Skip to main content
16,013,322 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi, i have an access database containing Tables ADDRESS_BOOK & USER_MASTER, i write and update statement to update address_book records which is running fine, but the same code i write for updating user_master then it is not giving the desired result like i'm updating USER_NAME and PASSWORD then it updates 0 instead of given text, the code is like this

VB
Public Function Edit(ByVal EmployeeID As String, ByVal EmployeeName As String, ByVal UserName As String, ByVal Password As String) As Boolean
       Try
           Dim StrSql As String = ""
           'StrSql = "UPDATE USER_MASTER SET EMPLOYEE_NAME = '" + EmployeeName.ToLower.ToString + "', USER_NAME = '" + UserName.ToLower.ToString + "' AND PASSWORD = '" + Password.ToLower.ToString + "' WHERE EMPLOYEE_ID = " + EmployeeID.ToString + " "
           StrSql = "UPDATE USER_MASTER SET EMPLOYEE_ID = " & EmployeeID & ", EMPLOYEE_NAME = '" & EmployeeName.ToLower.ToString & "', USER_NAME = '" & UserName.ToLower.ToString & "' AND PASSWORD = '" & Password.ToLower.ToString & "' WHERE EMPLOYEE_ID = " & EmployeeID.ToLower.ToString & ""
           objConnection.Conn = New OleDb.OleDbConnection(objConnection.ConnStr)
           objConnection.Conn.Open()
           objConnection.Cmd = New OleDb.OleDbCommand(StrSql, objConnection.Conn)
           objConnection.Cmd.ExecuteNonQuery()
           Return True
       Catch ex As Exception
           Return False
       End Try
   End Functi

on
Posted
Comments
Ankur\m/ 20-Oct-10 6:59am    
The commented query is correct already.
Rajesh Anuhya 20-Oct-10 7:08am    
no .., that is not correct, there sholud be a "," before "password =" instead of AND
Ankur\m/ 20-Oct-10 7:42am    
Oh yes, you are right. I didn't check the syntax. I meant, the logic behind the commented query is correct.

no need to update Employee Id coz on behalf of employee id u would be able to update ur table as that would be ur primary key.

use like it
UPDATE USER_MASTER SET EMPLOYEE_NAME = '"& EmployeeName.ToLower.ToString & "',USER_NAME = '" & UserName.ToLower.ToString & "',PASSWORD = '" & Password.ToLower.ToString & "'WHERE EMPLOYEE_ID = " & EmployeeID.ToLower.ToString & ""
 
Share this answer
 
v3
Comments
Ankur\m/ 20-Oct-10 7:43am    
[moved from answer]
sujit kodiyatar wrote:
thank rajesh

i tried as you said there should be , before password but if i do so then it throws Exception Syntax error in UPDATE statement, pls help me out
Try this:

VB
Dim StrSql As String = ""
StrSql = "UPDATE USER_MASTER SET EMPLOYEE_NAME = '" + EmployeeName.ToLower.ToString + "', USER_NAME = '" + UserName.ToLower.ToString + "', PASSWORD = '" + Password.ToLower.ToString + "' WHERE EMPLOYEE_ID = " + EmployeeID
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900