In C#, for Table-valued parameter I add a SqlParameter with 'SqlDbType' as 'Structured' and 'Value' as a C# DataTable. I want to extract this data later in my code.
- I want to verify if the SqlDbType/DbType is 'Structured'.
- If yes, and if the 'Value' is a 'DataTable', I want fetch the columnNames of its Columns and the data in the DataRows.
Below is the code for SqlParameter.
DataTable memoIdDt = new DataTable();
SqlParameter param = new SqlParameter ("memos", SqlDbType.Structured) { Value = memoIdDt, TypeName = "Table_Type_In_DB" };
Later I want to do something like the below (this is not the exact code).
//I am not able to use param.SqlDbType. I can use the param.DbType property.
//But it returns Object. So, not able to get the if clause right.
If(param.DbType == SqlDbType.Structued)
{
//foreach column in param.Value.Columns, print columnNames
//foreach DataRow in param.Value, print the array
}
Please help if you know how this can be achieved.
I think you can simply cast
param.Value
back to aDataTable
: