Übergeben einer Datentabelle an gespeichertes Verfahren - C#C#

Ein Treffpunkt für C#-Programmierer
Anonymous
 Übergeben einer Datentabelle an gespeichertes Verfahren - C#

Post by Anonymous »

Ich erstellt eine Datentabelle und übertrage sie als Parameter an die gespeicherte Prozedur. Nach der Ausführung stellt das gespeicherte Prozedur einen Ergebnissatz bereit.CREATE TYPE [dbo].[tvpKeyValue] AS TABLE(
[KeyID] [bigint] NULL,
[KeyValue] [bigint] NULL,
[KeyValueText] [varchar](500) NULL
)
< /code>
//Data table
DataTable InputRefTable = new DataTable();

//Adding columns
DataColumn col = null;
col = new DataColumn("KeyID", typeof(Int32));
InputRefTable.Columns.Add(col);
col = new DataColumn("KeyValue", typeof(Int64));
InputRefTable.Columns.Add(col);
col = new DataColumn("KeyValueText", typeof(String));
InputRefTable.Columns.Add(col);

//Adding row values
DataRow workRow;
foreach (var item in referenceListInfo)
{
string genName = string.Empty;
var refHeadingXid = context.ViewBookingReferenceDescription.FirstOrDefault(c => c.CompanyID == companyId && c.Description == item.name)?.ReferenceHeadingID;
if (refHeadingXid != null)
{
workRow = InputRefTable.NewRow();
workRow[0] = Convert.ToInt64(refHeadingXid);
workRow[1] = Convert.ToInt64(refHeadingXid);
workRow[2] = item.value;
InputRefTable.Rows.Add(workRow);
}
}

//Parameters
var param = new SqlParameter[]
{
new SqlParameter("@CompanyID", companyId),
new SqlParameter ("@RefData",InputRefTable)
};

param[1].SqlDbType = SqlDbType.Structured;
param[1].Direction = ParameterDirection.Input;
param[1].TypeName = "dbo.tvpKeyValue";
var rawSql = "EXECUTE usp_triprequest_GET_DynamicRefData @CompanyID, @RefData";
var a = context.ReferenceTableOutput.FromSql(rawSql, param).ToList();
< /code>
Früher habe ich die folgende Ausnahme erhalten, als ich nicht typename < /p>

Der Tabellen -Typ -Parameter '@Refdata' angegeben habe. Ausnahme < /p>

"Operand -Typ Clash: TVPKeyValue ist mit Bigint nicht kompatibel" < /p>
< /blockquote nicht kompatibel>

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post