Update command updating multiple rows in dataset

  • Thread starter Thread starter SHISHIR WAHI
  • Start date Start date
S

SHISHIR WAHI

Guest
Hi,

I am using following command to update my dataset:



UpdateCmd.CommandText = "update sl_employee set EMP_NAME=@name, EMP_TYPE=@type, GENDER=@gender, DOB=@dob, F_NAME=@fname, M_NAME=@mname, MOB_NO=@mobno, EC_NO=@ecno, P_ADDR=@paddr, P_CITY=" & cmbPCity.SelectedValue & ", P_STATE=" & cmbPState.SelectedValue & ", P_PIN=@ppin, C_ADDR=@caddr, C_CITY=" & cmbCCity.SelectedValue & ", C_STATE=" & cmbCState.SelectedValue & ", C_PIN=@cpin, [MODBY]=" & frmMain.UserID & ", [MODON]=getdate() where emp_id=@original_emp_id"

UpdateCmd.Connection = conSMS.sqlConn

UpdateCmd.Parameters.AddRange(New System.Data.SqlClient.SqlParameter() {

New System.Data.SqlClient.SqlParameter("@original_emp_id", System.Data.SqlDbType.Int, 0, System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0, Byte), "EMP_ID", System.Data.DataRowVersion.Original, Nothing),

New System.Data.SqlClient.SqlParameter("@name", System.Data.SqlDbType.VarChar, 0, "EMP_NAME"),

New System.Data.SqlClient.SqlParameter("@type", System.Data.SqlDbType.VarChar, 0, "EMP_TYPE"),

New System.Data.SqlClient.SqlParameter("@gender", System.Data.SqlDbType.VarChar, 0, "GENDER"),

New System.Data.SqlClient.SqlParameter("@dob", System.Data.SqlDbType.Date, 0, "DOB"),

New System.Data.SqlClient.SqlParameter("@fname", System.Data.SqlDbType.VarChar, 0, "F_NAME"),

New System.Data.SqlClient.SqlParameter("@mname", System.Data.SqlDbType.VarChar, 0, "M_NAME"),

New System.Data.SqlClient.SqlParameter("@mobno", System.Data.SqlDbType.VarChar, 0, "MOB_NO"),

New System.Data.SqlClient.SqlParameter("@ecno", System.Data.SqlDbType.VarChar, 0, "EC_NO"),

New System.Data.SqlClient.SqlParameter("@paddr", System.Data.SqlDbType.VarChar, 0, "P_ADDR"),

New System.Data.SqlClient.SqlParameter("@ppin", System.Data.SqlDbType.VarChar, 0, "P_PIN"),

New System.Data.SqlClient.SqlParameter("@caddr", System.Data.SqlDbType.VarChar, 0, "C_ADDR"),

New System.Data.SqlClient.SqlParameter("@cpin", System.Data.SqlDbType.VarChar, 0, "C_PIN")

})

adpEmployee.UpdateCommand = UpdateCmd

Private Function SaveRecord() As Boolean
If conSMS.ConnectSQLDB(My.Settings.SERVER, Schema, My.Settings.ISEC) = True Then
Try
BMB.EndCurrentEdit()
Create_Commands()
adpEmployee.Update(dsEmployee.Tables(0))
dsEmployee.Tables(0).AcceptChanges()

MsgBox("Record Saved Successfully!", MsgBoxStyle.Information, "Edit Record")
Return True
Catch ex As Exception
MsgBox(ex.Message, MsgBoxStyle.Critical, "Error")
Return False
End Try
Else
Return False
End If
End Function


But, somehow the command is updating more than the intended row, sometimes it updates the current row+first row(all the columns of the row are updated with the values of the current row) and sometimes all the records of the dataset are updated.

Please help! and revert if anything else is required from my side to analyze the problem.



Shishir

Continue reading...
 
Back
Top