Hi
I have audot trail for update / Edit data. I can use it into gridview.
But i want to use this code for INSERT/UPDATE/DELETE without gridview using VB.Net. I wnat to use in Single form. Please see my code.
Imports System
Imports System.Data
Imports System.Data.SqlClient
Imports System.Configuration
Imports System.Web
Imports System.Web.Configuration
Imports System.Collections.Generic
Imports System.Collections.Specialized
Public Class CurrentFields
'Private Shared ReadOnly _connectionString As String
Private _colName As String
Private _colValue As String
'Public Shared Sub New()
Public _connectionString As String = WebConfigurationManager.ConnectionStrings("POManagerConnectionString").ConnectionString
'End Sub
Public Property CurrColName As String
Get
Return _colName
End Get
Set(ByVal value As String)
_colName = value
End Set
End Property
Public Property CurrColValue As String
Get
Return _colValue
End Get
Set(ByVal value As String)
_colValue = value
End Set
End Property
Public Function GetCurrentFields(ByVal WhereField As String, ByVal ID As Integer, ByVal TableName As String) As List(Of CurrentFields)
Dim results As List(Of CurrentFields) = New List(Of CurrentFields)()
Dim ds As DataSet = New DataSet()
Dim dt As DataTable = Nothing
Dim dad As SqlDataAdapter = Nothing
Dim strSelectSql As String = "SELECT * FROM " & TableName & " where " & WhereField & "=" & ID
' strSelectSql += " WHERE " & WhereField = ID
Try
Dim conn As SqlConnection = New SqlConnection(_connectionString)
dad = New SqlDataAdapter(strSelectSql, conn)
dad.Fill(ds)
dt = ds.Tables(0)
For Each row As DataRow In dt.Rows
For Each column As DataColumn In dt.Columns
Dim currFlds As CurrentFields = New CurrentFields()
currFlds.CurrColName = column.ColumnName
currFlds.CurrColValue = row(column).ToString()
results.Add(currFlds)
Next
Next
Catch
End Try
Return results
End Function
End Class
Above class is fine.
But below code is working for gridview but not single form without gridview ? Please help
Private Sub GridView1_RowEditing(sender As Object, e As GridViewEditEventArgs) Handles GridView1.RowEditing
GridView1.SelectedIndex = e.NewEditIndex
'MsgBox(GridView1.SelectedRow.Cells(1).Text)
txtEditNominalCategories.Text = GridView1.SelectedRow.Cells(1).Text
txtEditNomOrCap.Text = GridView1.SelectedRow.Cells(2).Text
Dim ID As String = GridView1.Rows(e.NewEditIndex).Cells(0).Text
Dim currFlds As CurrentFields = New CurrentFields()
currFieldList = currFlds.GetCurrentFields("POItemID", ID, "PurchaseOrderItem")
Session("CurrData") = currFieldList
End Sub
Protected Sub GridView1_RowUpdated(ByVal sender As Object, ByVal e As GridViewUpdatedEventArgs) Handles GridView1.RowUpdated
currFieldList = CType(Session("CurrData"), List(Of CurrentFields))
For Each myDE As DictionaryEntry In e.NewValues
Dim i As Integer = 0
Dim key As String = myDE.Key.ToString()
For Each currFld As CurrentFields In currFieldList
If currFld.CurrColName = key Then
Exit For
End If
i += 1
Next
If myDE.Value IsNot Nothing Then
Dim newVal As String = myDE.Value.ToString()
If currFieldList(i).CurrColValue <> newVal Then
InsertAuditData.insertAuditChanges("Edit Purchase Order", "UPDATE", Session("Username"), key, currFieldList(i).CurrColValue, newVal)
End If
Else
If currFieldList(i).CurrColValue <> "" Then
InsertAuditData.insertAuditChanges("Edit Purchase Order", "UPDATE", Session("Username"), currFieldList(i).CurrColName, currFieldList(i).CurrColValue, "")
End If
End If
Next
End Sub