I would like to update data matched from one sql command but can't how to do?
From the code, when matched found it alerts "equal", then I would like to change emp to True and then update the change back to Database. But my code doesn't work. :-(
Pls kindly help.
Thanks alot.
VB.NET:
Private Sub btnCompare_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCompare.Click
sqlconn.Open()
SQLCmd = sqlconn.CreateCommand
SQLCmd.CommandText = "select emp_id,section,department,position from tblPayroll where type in ('IND','MGR') and emp_id not in (select emp_id from tblPayroll_prev where type in ('IND','MGR') and month_year in(select max(month_year) from tblPayroll_prev where type in ('IND','MGR')))"
rdr = SQLCmd.ExecuteReader()
Dim sec, dep, pos As String
Dim emp As Boolean = False
Dim ItemList As New ArrayList()
Dim manyArrayList As New ArrayList()
While rdr.Read()
sec = rdr.GetString(1)
dep = rdr.GetString(2)
pos = rdr.GetString(3)
ItemList.Add(sec)
ItemList.Add(dep)
ItemList.Add(pos)
manyArrayList.Add(ItemList)
End While
rdr.Close()
Dim sqlString As String
sqlString = "select section,department,position,employed from tblNew_IDL "
SQLCmd = sqlconn.CreateCommand
SQLCmd.CommandText = sqlString
DataGridView1.DataSource = Nothing
da = New SqlDataAdapter(sqlString, sqlconn)
commandBuilder = New SqlCommandBuilder(da)
ds = New DataSet()
da.Fill(ds, "Employ")
rdr = SQLCmd.ExecuteReader()
While rdr.Read()
sec = rdr.GetString(0)
dep = rdr.GetString(1)
pos = rdr.GetString(2)
emp = rdr.GetBoolean(3)
For i = 0 To ItemList.Count - 1
If i + 2 <= ItemList.Count - 1 Then
If String.Equals(Trim(ItemList.Item(i)), Trim(sec)) And String.Equals(Trim(ItemList.Item(i + 1)), Trim(dep)) And String.Equals(Trim(ItemList.Item(i + 2)), Trim(pos)) Then
MessageBox.Show("Equal")
emp = True
dt = ds.Tables("Employ")
da.Update(dt)
End If
End If
Next
End While
rdr.Close()
sqlconn.Close()
End Sub
From the code, when matched found it alerts "equal", then I would like to change emp to True and then update the change back to Database. But my code doesn't work. :-(
Pls kindly help.
Thanks alot.