Try
strSQL = "INSERT into SE_SEZMTA " _
& "(CD,NA" _
& ")" _
& " VALUES " _
& "(" _
& "@CD,@NA" _
& ")"
cmSQL = New SqlCommand(strSQL, cnSQLS)
cmSQL.Parameters.AddWithValue("@CD", CD)
cmSQL.Parameters.AddWithValue("@NA", txtNA.Text.ToString)
cmSQL.Transaction = trSQL
RET = cmSQL.ExecuteNonQuery
'
If RET = -1 Then
INSERTDB = "INSERTDBエラー"
End If
Catch ex As SqlException
INSERTDB = "INSERTDB:" & ex.Message
Catch ex As Exception
INSERTDB = "INSERTDB:" & ex.Message
End Try
'
名称にカンマや’がふくまれていても大丈夫です
mergeでは
mergeDB = ""
Try
strSQL = "MERGE INTO " & g_DBcommon & "..CO_GINKTA AS T " &
" USING (VALUES (@GCD, @SCD, @GNA, @SNA, @GNAK, @SNAK)) AS S (GCD, SCD, GNA, SNA, GNAK, SNAK) " &
" ON (T.GCD = S.GCD AND T.SCD = S.SCD) " &
" WHEN MATCHED THEN " &
" UPDATE SET GNA = S.GNA, SNA = S.SNA " &
" WHEN NOT MATCHED THEN " &
" INSERT (GCD, SCD, GNA, SNA, GNAK, SNAK) " &
" VALUES (S.GCD, S.SCD, S.GNA, S.SNA, S.GNAK, S.SNAK);"
cmSQL = New SqlCommand(strSQL, cnSQLS)
cmSQL.Parameters.AddWithValue("@GCD", GCD)
cmSQL.Parameters.AddWithValue("@SCD", SCD)
cmSQL.Parameters.AddWithValue("@GNA", cutKANMA(txtGNA.Text.ToString))
cmSQL.Parameters.AddWithValue("@SNA", cutKANMA(txtSNA.Text.ToString))
cmSQL.Parameters.AddWithValue("@GNAK", cutKANMA(txtGNAK.Text.ToString))
cmSQL.Parameters.AddWithValue("@SNAK", cutKANMA(txtSNAK.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
まとめてinsert
INSERT INTO YourTable (Column1, Column2)
VALUES
(‘Value1’, ‘Value2’),
(‘Value3’, ‘Value4’),
(‘Value5’, ‘Value6’);