Use oracleclient to operate the clob field ~

Source: Internet
Author: User
Tags oracleconnection

When I encountered an oracle SQL problem during the database installation package today, when I directly inserted more than 4000 characters using the insert statement, an error is reported, no matter what field type is used (varchar2 \ long \ clob has been tried and cannot solve the problem), I asked in the dev-club database version, xiaoxiang Jianqiang said that Oracle cannot directly insert strings above 4000, and introduced a previous ASP syntax to insert strings above 4000 characters.ArticleBut what I need is. net version. After reading the idea, find the AppendChunk method in msdn and find ASP. net has been discarded, but it provides another operation method, as follows:

Sqlconnection con = new sqlconnection ("Server = darkover; uid = sa; Pwd = password1; database = northwind ");
Sqldataadapter da = new sqldataadapter ("select * From myimages", con );
Sqlcommandbuilder mycb = new sqlcommandbuilder (DA );
Dataset DS = new dataset ("myimages ");

Da. missingschemaaction = missingschemaaction. addwithkey;
Filestream FS = new filestream (@ "C: \ winnt \ gone fishing. BMP", filemode. openorcreate, fileaccess. Read );

Byte [] mydata = new byte [fs. Length];
FS. Read (mydata, 0, system. Convert. toint32 (FS. Length ));

FS. Close ();

Da. Fill (DS, "myimages ");

Datarow myrow;
Myrow = Ds. Tables ["myimages"]. newrow ();

Myrow ["Description"] = "This wocould be description text ";
Myrow ["imgfield"] = mydata;
DS. Tables ["myimages"]. Rows. Add (myrow );
Da. Update (DS, "myimages ");

Con. Close ();

ThisCodeIt is an SQL server operation, but I already have some ideas. I changed the Oracle operation syntax as follows:

String strcon = "Data Source = ehr; user id = ehr; Password = ehr ";
OC. oracleconnection con = new system. Data. oracleclient. oracleconnection (strcon );
Con. open ();

oC. oraclecommand cmd2 = new system. data. oracleclient. oraclecommand ("select * From paycalculatemainlogic", con);
oC. oracledataadapter _ ADP = new system. data. oracleclient. oracledataadapter (cmd2);
_ ADP. insertcommand = new system. data. oracleclient. oraclecommand (
"insert into paycalculatemainlogic (mainlogicname, mainlogicid, mainscript, isdeleted, mainlogicversionid)" +
"values ('mainlock', '2017-e639-4a12-a2be-d2f63a2536ea ',: pmainscript, 0, 'mainlogicversionid') ", con);
oC. oracleparameter _ OP1 = new oC. oracleparameter ("pmainscript", OC. oracletype. clob);
_ op1.value = getsql ();
_ ADP. insertcommand. parameters. add (_ OP1);
_ ADP. insertcommand. executenonquery ();

OC. oraclecommand cmd3 = new system. Data. oracleclient. oraclecommand ("select * From paycalculatemainlogic", con );
_ ADP = new system. Data. oracleclient. oracledataadapter (cmd3 );
Dataset _ ds2 = new dataset ();
_ ADP. Fill (_ ds2, "logic ");

This. datagrid1.datasource = _ ds2.tables [0];

Con. Close ();

All is OK.

PS: The Oracle parameter is not the @ + parameter name in sqlserver, but the + parameter name and colon.


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.