Here is the answer I got.
public async Task SaveToDBTableV5()
{
using (SqlConnection connection = new SqlConnection(Properties.Settings.Default.Connection))
{
connection.Open();
SqlCommand cmd = new SqlCommand("dbo.INSERTEmailTestV2", connection);
cmd.CommandType = CommandType.StoredProcedure;
try
{
cmd.Parameters.AddWithValue("@EmailTstType", DataTable);
cmd.ExecuteNonQuery();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
}
CREATE TYPE [dbo].[EmailTstType] AS TABLE(
[ID] [int] NULL,
[TradeID] [int] NULL,
[Price] [decimal](18, 0) NULL,
[Quantity] [decimal](18, 0) NULL,
[TradeTime] [datetime] NULL,
[Symbol] [nvarchar](150) NULL,
[EventType] [nvarchar](150) NULL,
[IsMaker] [int] NULL,
[EventTime] [datetime] NULL,
[BuyerID] [int] NULL,
[SellerID] [int] NULL,
[Filled] [bit] NULL,
[Name] [nvarchar](100) NULL
)
CREATE PROCEDURE [dbo].[INSERTEmailTestV2]
@EmailTstType EmailTstType READONLY
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from -- interfering with SELECT statements.
SET NOCOUNT ON;
MERGE INTO dbo.EmailTest e1
USING @EmailTstType e2
ON e1.TradeID = e2.TradeID
WHEN NOT MATCHED THEN
INSERT VALUES (e2.TradeID, e2.Price, e2.Quantity, e2.TradeTime, e2.Symbol, e2.EventType,
e2.IsMaker, e2.EventTime, e2.BuyerID, e2.SellerID, e2.Filled, e2.Name);
END