|
database
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Consuming raw data from UDTs in ADO.NETI 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 appreciated. Leila [attached file: Type1.vb] |
|||||||||||||||||||||||