vb.netでフォーム上のtextboxを取り込みテーブルを更新する
Private Function mergeDB(ByVal cd As Integer) As String
Dim RET As Integer = 0
Dim DAT As String
mergeDB = ""
Try
' MERGE文を実行する
Dim strsql As String = "MERGE INTO " & g_DBcommon & "..CO_NOHITA AS Target " &
"USING (VALUES (@CD, @NA, @KNA, @YNO, @ADR1, @ADR2, @TEL, @FAX, @TANA, @MAIL, @KTEL)) AS S (CD, NA, KNA, YNO, ADR1, ADR2, TEL, FAX, TANA, MAIL, KTEL) " &
"ON Target.CD = S.CD " &
"WHEN MATCHED THEN " &
" UPDATE SET NA = S.NA, KNA = S.KNA, YNO = S.YNO, ADR1 = S.ADR1, ADR2 = S.ADR2, TEL = S.TEL, FAX = S.FAX, TANA = S.TANA, MAIL = S.MAIL, KTEL = S.KTEL " &
"WHEN NOT MATCHED THEN " &
" INSERT (CD, NA, KNA, YNO, ADR1, ADR2, TEL, FAX, TANA, MAIL, KTEL) " &
" VALUES (S.CD, S.NA, S.KNA, S.YNO, S.ADR1, S.ADR2, S.TEL, S.FAX, S.TANA, S.MAIL, S.KTEL);"
cmSQL = New SqlCommand(strSQL, cnSQLS)
cmSQL.Parameters.AddWithValue("@CD", cd)
cmSQL.Parameters.AddWithValue("@NA", cutKANMA(txtNA.Text.ToString))
cmSQL.Parameters.AddWithValue("@KNA", cutKANMA(txtKNA.Text.ToString))
cmSQL.Parameters.AddWithValue("@YNO", cutKANMA(txtYno.Text.ToString))
cmSQL.Parameters.AddWithValue("@ADR1", cutKANMA(txtAdr1.Text.ToString))
cmSQL.Parameters.AddWithValue("@ADR2", cutKANMA(txtAdr2.Text.ToString))
cmSQL.Parameters.AddWithValue("@TEL", cutKANMA(txtTel.Text.ToString))
cmSQL.Parameters.AddWithValue("@FAX", cutKANMA(txtFax.Text.ToString))
cmSQL.Parameters.AddWithValue("@TANA", cutKANMA(txtTana.Text.ToString))
cmSQL.Parameters.AddWithValue("@MAIL", cutKANMA(txtMAIL.Text.ToString))
cmSQL.Parameters.AddWithValue("@KTEL", cutKANMA(txtKTEL.Text.ToString))
cmSQL.Transaction = trSQL
RET = cmSQL.ExecuteNonQuery
'
If RET = -1 Then
mergeDB = "mergeDBエラー"
End If
'
Catch ex As SqlException
mergeDB = "mergeDB:" & ex.Message
Catch ex As Exception
mergeDB = "mergeDB:" & ex.Message
End Try
End Function