Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsVB SyntaxEnterprise DevelopmentDatabase AccessControlsCOMWin APICrystal ReportDeploymentGeneralGeneral 2
Related Topics
VB.NET / ASP.NETMS SQL ServerMS AccessOther Database ProductsMore Topics ...

VB Forum / Database Access / September 2004



Tip: Looking for answers? Try searching our database.

DataType Text in MSSQL

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Grant - 24 Sep 2004 13:34 GMT
I am having hard time understanding what I need to do to read from the
column that is set to TEXT datatype. The book example that I have uses
stored procedures and I still cannot understand it. I also don't think I can
use store procedure for this certain customer. Is there a way to read it
with out the store procedure if so please tell me where I can go to learn
how to do it. Thanks
Veign - 24 Sep 2004 15:27 GMT
Have you tried just doing a "SELECT myTextField FROM myTable"

Where:
myTextField is the name of your text field
myTable is the name of the table

Signature

Chris Hanscom
MVP (Visual Basic)
http://www.veign.com
--

> I am having hard time understanding what I need to do to read from the
> column that is set to TEXT datatype. The book example that I have uses
> stored procedures and I still cannot understand it. I also don't think I can
> use store procedure for this certain customer. Is there a way to read it
> with out the store procedure if so please tell me where I can go to learn
> how to do it. Thanks
Grant - 24 Sep 2004 15:37 GMT
What!!! I beat my head up to figure out how to retrieve the value.

Why does it not work if I use * to select all fields along with mytextField?

> Have you tried just doing a "SELECT myTextField FROM myTable"
>
[quoted text clipped - 9 lines]
> > with out the store procedure if so please tell me where I can go to learn
> > how to do it. Thanks
Veign - 24 Sep 2004 15:42 GMT
Not sure but you should never use the * to select all fields.  Always
explicitly list your fields names.

Signature

Chris Hanscom
MVP (Visual Basic)
http://www.veign.com
--

> What!!! I beat my head up to figure out how to retrieve the value.
>
[quoted text clipped - 14 lines]
> learn
> > > how to do it. Thanks
Val Mazur - 25 Sep 2004 04:22 GMT
Hi,

Reason for this is just limitation in OLEDB. When you need to work with any
BLOB-type field (like TEXT, BINARY etc), then these fields should be last in
a list of selected fields inside of your query. It means if you specify *
and your text field located somewhere in a middle, then it will not work.
Your query should look like

SELECT Field1, .....FieldN, myTextField FROM myTable

Signature

Val Mazur
Microsoft MVP

> What!!! I beat my head up to figure out how to retrieve the value.
>
[quoted text clipped - 17 lines]
> learn
>> > how to do it. Thanks
Mark J. McGinty - 26 Sep 2004 14:27 GMT
That will work until myTextField (actually, until the sum size of all fields
returned) contains more than 8060 bytes.  Beyond that you'll need to use
either GetChunk/AppendChunk, or ADODB.Stream.  (Samples on request.)

-Mark

> Have you tried just doing a "SELECT myTextField FROM myTable"
>
[quoted text clipped - 9 lines]
>> with out the store procedure if so please tell me where I can go to learn
>> how to do it. Thanks
Grant - 29 Sep 2004 13:07 GMT
Thanks for the replies.

Mark, I would like the sample if it is not too late. Thanks.

> That will work until myTextField (actually, until the sum size of all fields
> returned) contains more than 8060 bytes.  Beyond that you'll need to use
[quoted text clipped - 15 lines]
> >> with out the store procedure if so please tell me where I can go to learn
> >> how to do it. Thanks
Mark J. McGinty - 29 Sep 2004 15:35 GMT
> Thanks for the replies.
>
> Mark, I would like the sample if it is not too late. Thanks.

Not too late at all.  Below are two functions, the first will write the
contents of StringBuffer to the field specified in FieldName.  The recordset
rs is assumed to be open and the contents of FieldName must match a field
text in it (of course.)

The second function is much the same, except that it accepts the FQ name of
a file, and writes the contents of that file to a column of type image.

Hope this helps,
Mark

Sub StuffText(StringBuffer As String, _
   FieldName As String, _
   rs As ADODB.Recordset _
)

   Dim s As ADODB.Stream
   Set s = New ADODB.Stream
   s.Mode = adModeReadWrite
   s.Type = adTypeText

   ' By default a text stream will have a unicode char set
   ' which must be changed if you're going to use ANSI data
   '
   ' Since you're writing a field of type text the default char set
   ' won't work. If you're writing ntext, leave it as default
   '
   s.Charset = "Windows-1252"  ' setting may depend on locale/collation

   s.Open
   s.WriteText StringBuffer
   s.Position = 0
   rs.Fields(FieldName).Value = s.ReadText()

   rs.Update
   s.Close
   Set s = Nothing

End Sub

Sub StuffBlob(FileName As String, _
   FieldName As String, _
   rs As ADODB.Recordset _
)
   Dim s As ADODB.Stream
   Set s = New ADODB.Stream
   s.Mode = adModeReadWrite
   s.Type = adTypeBinary
   s.Open

   ' load binary contents of into stream
   '
   s.LoadFromFile FileName
   s.Position = 0
   rs.Fields(FieldName).Value = s.Read()

   rs.Update
   s.Close
   Set s = Nothing

End Sub
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.