hi there
here i will share the way to handle quote (') during coding with VB.Net
sometimes we will have data such as (MAT'L) that quote is definitely forbidden when we are use the data.
create a function as below :
Public Function Ganti(ByVal Kata As String) As String
Ganti = Replace(Kata, "'", "''")
End Function
and here is this how you gonna use that function, read carefully
Public Sub InsertDataDefect(ByVal Row As Integer)
Dim DefectName As String = dgvInputBMISDetail.Rows(Row).Cells("dgvInputBMISDetailDefectName").Value.ToString
Koneksi()
cmd = New SqlCommand("SELECT * FROM dbo.mstDEFECT WHERE (ActiveTo IS NULL) AND DefectName='" & Ganti(DefectName) & "'", Conn)
rd = cmd.ExecuteReader
rd.Read()
If rd.HasRows Then
With dgvInputBMISDetail
.Rows(Row).Cells("dgvInputBMISDetailRecNoDefect").Value = rd.Item("AutoRecordNoDefect")
.Rows(Row).Cells("dgvInputBMISDetailDefectNo").Value = rd.Item("DefectNo")
End With
End If
Conn.Close()
End Sub
here i will share the way to handle quote (') during coding with VB.Net
sometimes we will have data such as (MAT'L) that quote is definitely forbidden when we are use the data.
create a function as below :
Public Function Ganti(ByVal Kata As String) As String
Ganti = Replace(Kata, "'", "''")
End Function
and here is this how you gonna use that function, read carefully
Public Sub InsertDataDefect(ByVal Row As Integer)
Dim DefectName As String = dgvInputBMISDetail.Rows(Row).Cells("dgvInputBMISDetailDefectName").Value.ToString
Koneksi()
cmd = New SqlCommand("SELECT * FROM dbo.mstDEFECT WHERE (ActiveTo IS NULL) AND DefectName='" & Ganti(DefectName) & "'", Conn)
rd = cmd.ExecuteReader
rd.Read()
If rd.HasRows Then
With dgvInputBMISDetail
.Rows(Row).Cells("dgvInputBMISDetailRecNoDefect").Value = rd.Item("AutoRecordNoDefect")
.Rows(Row).Cells("dgvInputBMISDetailDefectNo").Value = rd.Item("DefectNo")
End With
End If
Conn.Close()
End Sub
Comments
Post a Comment