Table Value Parameter using generics

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
hi experts,
i want to pass table value parameter using ado.net to stored procedure. I have seen that using DataTable it is possible, but i want to write custom iterator for the same without using DataTable.
Is is possible to write generic iterator for different table valued parameter.
eg
<span size="2" style="font-size:small <span lang="EN-US" style="color:blue; line-height:115%; font-size:10pt public<span lang="EN-US" style="line-height:115%; font-size:10pt
<span style="color:blue class <span style="color:#2b91af myData <br/>
{<br/>
<span style="color:blue public <span style="color:blue
int CustomerId { <span style="color:blue get; <span style="color:blue
set; }<br/>
<span style="color:blue public <span style="color:blue
string CustomerName { <span style="color:blue get; <span style="color:blue
set; }<br/>
}<br/>
<span face="Verdana" size="2" style="font-family:Verdana; font-size:small <br/>
<span lang="EN-US" style="color:blue; line-height:115%; font-size:10pt public<span lang="EN-US" style="line-height:115%; font-size:10pt
<span style="color:blue class <span style="color:#2b91af myDataCollection :
<span style="color:#2b91af List<<span style="color:#2b91af myData>,
<span style="color:#2b91af IEnumerable<<span style="color:#2b91af SqlDataRecord><br/>
{<br/>
<span style="color:#2b91af IEnumerator<<span style="color:#2b91af SqlDataRecord>
<span style="color:#2b91af IEnumerable<<span style="color:#2b91af SqlDataRecord>.GetEnumerator()<br/>
{<br/>
<span style="color:#2b91af SqlDataRecord ret =
<span style="color:blue new <span style="color:#2b91af SqlDataRecord(<br/>
<span style="color:blue
new <span style="color:#2b91af SqlMetaData(<span style="color:#a31515 "CustomerId",
<span style="color:#2b91af SqlDbType.Int),<br/>
<span style="color:blue
new <span style="color:#2b91af SqlMetaData(<span style="color:#a31515 "CustomerName",
<span style="color:#2b91af SqlDbType.VarChar, 20)<br/>
);<br/>
<br/>
<span style="color:blue foreach (<span style="color:#2b91af myData data
<span style="color:blue in <span style="color:blue this)<br/>
{<br/>
ret.SetInt32(0, data.CustomerId);<br/>
ret.SetString(1, data.CustomerName);<br/>
<span style="color:blue
yield <span style="color:blue return ret;<br/>
}<br/>
}<br/>
}<br/>
<span lang="EN-US" style="color:#2b91af; line-height:115%; font-size:10pt myDataCollection<span lang="EN-US" style="line-height:115%; font-size:10pt myTable =
<span style="color:blue new <span style="color:#2b91af myDataCollection();<br/>
myTable.Add(<span style="color:blue new <span style="color:#2b91af myData { CustomerId = 4, CustomerName =
<span style="color:#a31515 "Jignesh" });<br/>
myTable.Add(<span style="color:blue new <span style="color:#2b91af myData { CustomerId = 5, CustomerName =
<span style="color:#a31515 "Tejas" });<br/>
myTable.Add(<span style="color:blue new <span style="color:#2b91af myData { CustomerId = 6, CustomerName =
<span style="color:#a31515 "Rakesh" });
<span size="2" style="font-size:small <span lang="EN-US" style="line-height:115%; font-size:10pt <br/>

<span size="2" style="font-size:small <span lang="EN-US" style="line-height:115%; font-size:10pt The above code only works for
<span size="2" style="font-size:small <span lang="EN-US" style="line-height:115%; font-size:10pt <span style="color:#2b91af myData
class. Can the above code be made dynamic. for example making using of T.
<span size="2" style="font-size:small <span lang="EN-US" style="line-height:115%; font-size:10pt <span size="2" style="font-size:small <span lang="EN-US" style="color:blue; line-height:115%; font-size:10pt public<span lang="EN-US" style="line-height:115%; font-size:10pt
<span style="color:blue class <span style="color:#2b91af myDataCollection<T> :
<span style="color:#2b91af List<T>, <span style="color:#2b91af IEnumerable<<span style="color:#2b91af SqlDataRecord> is it possible.

View the full article
 

Similar threads

Back
Top