Previous Thread:   Possible to store public shared variables in SQL Server 2005 ?

2/18/2006 10:42:25 AM    Consuming raw data from UDTs in ADO.NET
Hi,  
  
I have used the implementation of Point UDT exactly from MSDN:  
  
ms-help://MS.MSDNQTR.v80.en/MS.MSDN.v80/MS.SQL.v2005.en/denet9/html/1e5b43b3-4971-45ee-a591-3f535e2ac722.htm  
  
I have attached Type1.vb to this post. I have problem with binding UDTs as  
  
bytes. The example in this page:  
  
ms-help://MS.MSDNQTR.v80.en/MS.MSDN.v80/MS.VisualStudio.v80.en/WD_ADONET/html/55ba599e-97e7-4ea5-a980-f09bbfab8396.htm  
  
only returns the raw binary data in console but I need the string format. I  
  
also paste the code here:  
  
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As  
  
System.EventArgs) Handles Button2.Click  
  
Dim connectionString As String = GetConnectionString()  
  
Using cnn As New SqlConnection(connectionString)  
  
cnn.Open()  
  
Dim cmd As New SqlCommand( _  
  
"SELECT ID, Pnt FROM dbo.Points", cnn)  
  
Dim rdr As SqlDataReader  
  
rdr = cmd.ExecuteReader  
  
While rdr.Read()  
  
' Retrieve the value of the Primary Key column  
  
Dim id As Int32 = rdr.GetInt32(0)  
  
' Retrieve the raw bytes into a byte array  
  
Dim buffer(31) As Byte  
  
Dim byteCount As Integer = _  
  
CInt(rdr.GetBytes(1, 0, buffer, 0, 31))  
  
' Format and print bytes  
  
Dim str As New System.Text.StringBuilder  
  
str.AppendFormat("ID={0} Point=", id)  
  
Dim i As Integer  
  
For i = 0 To (byteCount - 1)  
  
str.AppendFormat("{0:x}", buffer(i))  
  
Next  
  
Console.WriteLine(str.ToString)  
  
End While  
  
rdr.Close()  
  
Console.WriteLine("done")  
  
End Using  
  
End Sub  
  
-------------------------  
  
Populating Point table:  
  
create table Points(  
  
id int identity primary key,  
  
pnt point)  
  
go  
  
INSERT points(pnt) VALUES('0,0')  
  
INSERT points(pnt) VALUES('9,3')  
  
INSERT points(pnt) VALUES('6,3')  
  
INSERT points(pnt) VALUES('7,4')  
  
SELECT ID, Pnt FROM Points  
  
-------------------------  
  
Any help would be greatly appreciate5R:6%L:7IA8FQE*"D^(%\-"CQ-:6-R  
  
M;W-O9G0N4W%L4V5R=F5R+E-E<G9E<BY3<6Q5<V5R1&5F:6YE9%1Y<&4H1F]R  
  
M;6%T+DYA=&EV92P@27-">71E3W)D97)E9#H]5')U92D^(%\-"E!U8FQI8R!3  
  
M=')U8W1U<F4@4&]I;G0-"B @("!);7!L96UE;G1S($E.=6QL86)L90T*(" @  
  
M(%!R:79A=&4@:7-?3G5L;"!!<R!";V]L96%N#0H@(" @4')I=F%T92!?>"!!  
  
M<R!);G0S,@T*(" @(%!R:79A=&4@7WD@07,@26YT,S(-"@T*(" @(%!U8FQI  
  
M8R!/=F5R<FED97,@1G5N8W1I;VX@5&]3=')I;F<H*2!!<R!3=')I;F<-"B @  
  
M(" @(" @268@364N27-.=6QL(%1H96X-"B @(" @(" @(" @(%)E='5R;B B  
  
M3E5,3"(-"B @(" @(" @16QS90T*(" @(" @(" @(" @1&EM(&)U:6QD97(@  
  
M07,@4W1R:6YG0G5I;&1E<B ]($YE=R!3=')I;F="=6EL9&5R#0H@(" @(" @  
  
M(" @("!B=6EL9&5R+D%P<&5N9"A?>"D-"B @(" @(" @(" @(&)U:6QD97(N  
  
M07!P96YD*"(L(BD-"B @(" @(" @(" @(&)U:6QD97(N07!P96YD*%]Y*0T*  
  
M(" @(" @(" @(" @4F5T=7)N(&)U:6QD97(N5&]3=')I;F<-"B @(" @(" @  
  
M16YD($EF#0H@(" @16YD($9U;F-T:6]N#0H-"B @("!0=6)L:6,@4F5A9$]N  
  
M;'D@4')O<&5R='D@27-.=6QL*"D@07,@0F]O;&5A;B!?#0H@(" @(" @26UP  
  
M;&5M96YT<R!)3G5L;&%B;&4N27-.=6QL#0H@(" @(" @($=E= T*(" @(" @  
  
M(" @(" @4F5T=7)N("AI<U].=6QL*0T*(" @(" @("!%;F0@1V5T#0H@(" @  
  
M16YD(%!R;W!E<G1Y#0H-"@T*(" @(%!U8FQI8R!3:&%R960@4F5A9$]N;'D@  
  
M4')O<&5R='D@3G5L;"@I($%S(%!O:6YT#0H@(" @(" @($=E= T*(" @(" @  
  
M(" @(" @1&EM('!T($%S($YE=R!0;VEN= T*(" @(" @(" @(" @<'0N:7-?  
  
M3G5L;" ](%1R=64-"B @(" @(" @(" @(%)E='5R;B H<'0I#0H@(" @(" @  
  
M($5N9"!'970-"B @("!%;F0@4')O<&5R='D-"@T*(" @(#Q3<6Q-971H;V0H  
  
M3VY.=6QL0V%L;#H]1F%L<V4I/B!?#0H@(" @4'5B;&EC(%-H87)E9"!&=6YC  
  
M=&EO;B!087)S92A">59A;"!S($%S(%-Q;%-T<FEN9RD@07,@4&]I;G0-"B @  
  
M(" @(" @268@<RY)<TYU;&P@5&AE;@T*(" @(" @(" @(" @4F5T=7)N($YU  
  
M;&P-"B @(" @(" @16YD($EF#0H-"B @(" @(" @)R!087)S92!I;G!U="!S  
  
M=')I;F<@:&5R92!T;R!S97!A<F%T92!O=70@<&]I;G1S+@T*(" @(" @("!$  
  
M:6T@<'0@07,@3F5W(%!O:6YT*"D-"B @(" @(" @1&EM('AY*"D@07,@4W1R  
  
M:6YG(#T@<RY686QU92Y3<&QI="@B+"(N5&]#:&%R07)R87DH*2D-"B @(" @  
  
M(" @<'0N6" ]($EN=#,R+E!A<G-E*'AY*# I*0T*(" @(" @("!P="Y9(#T@  
  
M26YT,S(N4&%R<V4H>'DH,2DI#0H@(" @(" @(%)E='5R;B!P= T*(" @($5N  
  
M9"!&=6YC=&EO;@T*#0H@(" @4'5B;&EC(%!R;W!E<G1Y(%@H*2!!<R!);G0S  
  
M,@T*(" @(" @("!'970-"B @(" @(" @(" @(%)E='5R;B H364N7W@I#0H@  
  
M(" @(" @($5N9"!'970-"@T*(" @(" @("!3970H0GE686P@5F%L=64@07,@  
  
M26YT,S(I#0H@(" @(" @(" @("!?>" ](%9A;'5E#0H@(" @(" @($5N9"!3  
  
M970-"B @("!%;F0@4')O<&5R='D-"@T*(" @(%!U8FQI8R!0<F]P97)T>2!9  
  
M*"D@07,@26YT,S(-"B @(" @(" @1V5T#0H@(" @(" @(" @("!2971U<FX@  
  
M*$UE+E]Y*0T*(" @(" @("!%;F0@1V5T#0H-"B @(" @(" @4V5T*$)Y5F%L  
  
M(%9A;'5E($%S($EN=#,R*0T*(" @(" @(" @(" @7WD@/2!686QU90T*(" @  
  
M(" @("!%;F0@4V5T#0H@(" @16YD(%!R;W!E<G1Y#0H-"B @(" G($1I<W1A  
  
M;F-E(&9R;VT@,"!T;R!0;VEN="X-"B @(" \4W%L365T:&]D*$]N3G5L;$-A  
  
M;&PZ/49A;'-E*3X@7PT*(" @(%!U8FQI8R!&=6YC=&EO;B!$:7-T86YC92@I  
  
M($%S($1O=6)L90T*(" @(" @("!2971U<FX@1&ES=&%N8V5&<F]M6%DH,"P@  
  
M,"D-"B @("!%;F0@1G5N8W1I;VX-"@T*(" @("<@1&ES=&%N8V4@9G)O;2!0  
  
M;VEN="!T;R!T:&4@<W!E8VEF:65D('!O:6YT+@T*(" @(#Q3<6Q-971H;V0H  
  
M3VY.=6QL0V%L;#H]1F%L<V4I/B!?#0H@(" @4'5B;&EC($9U;F-T:6]N($1I  
  
M<W1A;F-E1G)O;2A">59A;"!P1G)O;2!!<R!0;VEN="D@07,@1&]U8FQE#0H@  
  
M(" @(" @(%)E='5R;B!$:7-T86YC949R;VU862AP1G)O;2Y8+"!P1G)O;2Y9  
  
M*0T*(" @($5N9"!&=6YC=&EO;@T*#0H@(" @)R!$:7-T86YC92!F<F]M(%!O  
  
M:6YT('1O('1H92!S<&5C:69I960@>"!A;F0@>2!V86QU97,N#0H@(" @/%-Q  
  
M;$UE=&AO9"A/;DYU;&Q#86QL.CU&86QS92D^(%\-"B @("!0=6)L:6,@1G5N  
  
M8W1I;VX@1&ES=&%N8V5&<F]M6%DH0GE686P@:7@@07,@26YT,S(L($)Y5F%L  
  
M(&EY($%S($EN=#,R*2!?#0H@(" @(" @($%S($1O=6)L90T*(" @(" @("!2  
  
M971U<FX@36%T:"Y3<7)T*$UA=&@N4&]W*&EX("T@7W@L(#(N,"D@*R!-871H  
  
M+E!O=RAI>2 M(%]Y+" R+C I*0T*(" @($5N9"!&=6YC=&EO;@T*#0H-"D5N  
  
/9"!3=')U8W1U<F4-"@T*  
  
`  
  
end