Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click
Try
MessageBox.Show("Confirm to Delete Import Name ?", "Delete", MessageBoxButtons.YesNo, MessageBoxIcon.Question)
For I As Integer = 0 To Me.dgvImportType.RowCount - 1
If Me.dgvImportType.Rows(I).Cells("IMNAME").Value IsNot Nothing Then
Dim DELETE As String = Me.dgvImportType.Rows(I).Cells("DELETE").Value.ToString
If DELETE = "True" Then
' MessageBox.Show("Confirm to Delete Import Name ?", "Delete", MessageBoxButtons.YesNo, MessageBoxIcon.Question)
'Delete Data
s = ""
s &= "DELETE FROM EBIMTYPE "
s &= "WHERE IMCOMP = '" & Me.lblCompNo.Text & "' "
s &= "AND IMNAME = '" & Me.dgvImportType.Rows(I).Cells("IMNAME").Value.ToString & "' "
SQLConnect.Execute(s)
Else
If Me.dgvImportType.Rows(I).Cells("IMNAME").Value IsNot Nothing Then
s = ""
s &= "SELECT IMNAME FROM EBIMTYPE"
s &= "WHERE IMCOMP = '" & Me.lblCompNo.Text & "' "
s &= "AND IMNAME = '" & Me.dgvImportType.Rows(I).Cells("IMNAME").Value.ToString & "' "
Dim dtComp As New DataTable
dtComp = SQLConnect.SelectDataTable(s)
If dtComp.Rows.Count > 0 Then
'Update Data
s = ""
s &= "UPDATE EBIMTYPE SET IMNAME = '" & Me.dgvImportType.Rows(I).Cells("IMNAME").Value.ToString & "', "
s &= "IMTYPE = '" & Me.dgvImportType.Rows(I).Cells("IMTYPE").Value.ToString & "', "
s &= "IMFORMAT = '" & Me.dgvImportType.Rows(I).Cells("IMFORMAT").Value.ToString & "', "
s &= "WHERE IMCOMP = '" & Me.lblCompNo.Text & "' "
s &= "AND IMNAME = '" & Me.dgvImportType.Rows(I).Cells("IMNAME").Value.ToString & "' "
Else
'Add New Data
s = ""
s &= "INSERT INTO EBIMTYPE (IMNAME, IMTYPE, IMFORMAT) "
s &= "VALUES ('" & Me.dgvImportType.Rows(I).Cells("IMNAME").Value.ToString & "', "
s &= " '" & Me.dgvImportType.Rows(I).Cells("IMTYPE").Value.ToString & "', "
s &= " '" & Me.dgvImportType.Rows(I).Cells("IMFORMAT").Value.ToString & "') "
End If
SQLConnect.Execute(s)
End If
End If
End If
Next
MessageBox.Show("Update Data is Successfully !!!", "Save", MessageBoxButtons.OK, MessageBoxIcon.Information)
Catch ex As Exception
MsgBox(ex.Message, MsgBoxStyle.Critical)
End Try
GetDefaultGrid()
End Sub
Tag : ASP.NET, Ms SQL Server 2005, VBScript, Crystal Report, Web (ASP.NET), VS 2008 (.NET 3.x)