I am trying to populate specific datatable values into a table. I am using the table value parameter. While adding the tabletype parameter i am thrown to no mapping exists. Can you find the bug in this part.
Below is my .NET Call
cmdabsSQL = dbabsSQL.CreateCommand()
cmdabsSQL.CommandText = "SP_INS_ResponseTable"
cmdabsSQL.CommandType = CommandType.StoredProcedure
cmdabsSQL.Parameters.Clear()
With dbabsSQL
.AddInParameter(cmdabsSQL, "@SystemName", DbType.String, SourceSysName)
.AddInParameter(cmdabsSQL, "@ClientName", DbType.String, ClientName)
.AddInParameter(cmdabsSQL, "@TableValueTypeII", SqlDbType.Structured, tablevaluedParam)
.AddOutParameter(cmdabsSQL, PARAM_OUT_SQLMSG, DbType.Int32, 100)
End With
intResult = dbBRLASQL.ExecuteNonQuery(cmdBRLASQL)
The tablevaluedParam is decalred like below.
Dim tablevaluedParam As DataTable = dstDataset.Tables(1)
here dstDataset has two datatables and the values in the dstDataset tables are populated by a query.I am just mapping the recieved datatable to the type created. Below is my type
CREATE TYPE TableValueTypeII AS TABLE
(ResultId BIGINT,
AccountId nvarchar(255),
RecStatusDesc varchar(100),
MatchCount int)
And this is my stored proc part
Insert into ResponseTable(SrceSysNm,ClntId,GrpId,PrvdId,FileNm,AccId,RestId,
RespSendIn,CreatTs,LstUpdtTs,UserId)
select @SystemName,@ClientName,null,null,null,AccountId,ResultId,0,
GETDATE(),GETDATE(),'Batch' from @TableValueTypeII
The dataTable is in the same arrangement of the type created.
You could create dynamic sql like below:
Then pass the table name as a simple string value.
Note: Please check for single quotes while forming dynamic sql