Reprinted: Type of the text and Image Fields in SQL2000.

Source: Internet
Author: User

The following content is reproduced in http://www.cnblogs.com/greatqn/archive/2007/03/21/637117.html,
I hope the landlord will not mind. I have already indicated the source.
To read and write text during storage, you must use readtext updatetext writetext for operations.

In C #, values can be obtained directly using select text from table.

During the update and add operations, use @ text to pass the text value, and assign values normally.

String is directly assigned to the text type.

Byte [] for the image type

Insert:

String strsql = "insert into [DBO]. [tableimg] ([img]) values (@ IMG )";
Using (system. Data. sqlclient. sqlconnection myconnection = new system. Data. sqlclient. sqlconnection (commconfig. infodbconnectstring ))
{
System. Data. sqlclient. sqlcommand mycommand = new system. Data. sqlclient. sqlcommand (strsql, myconnection );
Myconnection. open ();
String STR = new string ('x', 100000 );
Byte [] bytes = system. Text. encoding. Default. getbytes (Str. tochararray ());

Sqlparameter sp = new sqlparameter ("@ IMG", sqldbtype. Image );
Sp. value = bytes;

Mycommand. Parameters. Add (SP );
Int Re = mycommand. executenonquery ();

Mycommand. Dispose ();
Myconnection. Close ();
}

Select: String strsql = "select [ID], [img] from [DBO]. [tableimg] Where id = 1 ";

Using (system. Data. sqlclient. sqlconnection myconnection = new system. Data. sqlclient. sqlconnection (commconfig. infodbconnectstring ))
{
System. Data. sqlclient. sqlcommand mycommand = new system. Data. sqlclient. sqlcommand (strsql, myconnection );
Myconnection. open ();

Sqldatareader DR = mycommand. executereader ();
While (dr. Read ())
{
Byte [] bytes = (byte []) Dr [1];
String STR = system. Text. encoding. Default. getstring (bytes );
}

Mycommand. Dispose ();
Myconnection. Close ();
}

This article is reprinted in http://www.cnblogs.com/greatqn/archive/2007/03/21/637117.html

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.