C # Call the recordset. addnew method of ADO.

Source: Internet
Author: User
WebService is used in the project, C # is used for compiling, and components written in VB are called. ADO is used for VB components. Some methods need to pass recordset, but recordset in C. the addnew method is different from that in VB, because C # does not have the default parameter.
In C #, the prototype of addnew is addnew (Object fieldlist, object ValueList). It is confused by its parameter type at the beginning, and it is thought that the object array should be used, however, parameters are not in the form of arrays. They can be queried on the Internet, and finally find a solution to achieve similar implementation with VB.CodeAs follows:
Prjcommon. c_ I _receivegoods Rev
= New Prjcommon. c_ I _receivegoodsclass ();
Object Missing = System. reflection. Missing. value;
Rev. get_icommon_data (). addnew (missing, missing );
Rev. get_icommon_data (). Fields [rev. articleno]. Value
= Rd. articleno;
Rev. get_icommon_data (). Fields [rev. classid]. Value
= Rd. classid;
Rev. get_icommon_data (). Fields [rev. datetime]. Value
= Rd. revdatetime;
Rev. get_icommon_data (). Fields [rev. isprocessing]. Value
= Convert. toint32 (RD. processing );
Rev. get_icommon_data (). Fields [rev. Length]. Value
= Rd. length;
Rev. get_icommon_data (). Fields [rev. operatorid]. Value
= Rd. operatorid;
Rev. get_icommon_data (). Fields [rev. orollno]. Value
= Rd. orollno;
Rev. get_icommon_data (). Fields [rev. porderid]. Value
= Rd. porderid;
Rev. get_icommon_data (). Fields [rev. porderitem]. Value
= Rd. porderitem;
Rev. get_icommon_data (). Fields [rev. qty]. Value
= Rd. qty;
Rev. get_icommon_data (). Fields [rev. Width]. Value
= Rd. width;
Rev. get_icommon_data (). Update (missing, missing );

Get_icommon_data () is recordset.
The most important thing is the object missing.=System. reflection. Missing. value.

attached information found online:
comment from drichards
date: 01 / 13 / 2005 07 : 30am PST
comment

It turnsOutThat either of those methods worksIfYou takeOutThe"Mode = read;"From the connection open statementInMy first code sample. Otherwise the connectionIsRead-Only.

Here' S the syntax for the various options:

Object RV = System. reflection. Missing. value;
// Single insert
Cxn. Execute ( " Insert into dimension (dimension_id, dimension_name) values (22, 'First _ new_dim ') " , Out Ra ,( Int ) ADODB. executeoptionenum. adexecutenorecords );

// Prepared command with parameters-you can keep setting new values for the Params and calling execute again
ADODB. Command cmd =   New ADODB. commandclass ();
Cmd. activeconnection
= Cxn;
String Parmval =   " Next_new_dim " ;
Cmd. commandtext
=   " Insert into dimension (dimension_id, dimension_name) values (?, ?) " ;
Cmd. Prepared
=   True ;
Cmd. Parameters. append (CMD. createparameter (
" ? _ 1 " , ADODB. datatypeenum. adinteger, ADODB. parameterdirectionenum. adparaminput, 4 , 32 ));
Cmd. Parameters. append (CMD. createparameter (
" ? _ 2 " , ADODB. datatypeenum. adchar, ADODB. parameterdirectionenum. adparaminput, parmval. length, parmval ));
Cmd. Execute (
Out Ra, Ref RV ,( Int ) ADODB. commandtypeenum. ad1_text + ( Int ) ADODB. executeoptionenum. adexecutenorecords );

// Use A recordset
ADODB. recordset rsta =   New ADODB. recordsetclass ();
Rsta. Open (
" Dimension " , Cxn, ADODB. cursortypeenum. adopenkeyset, ADODB. locktypeenum. adlockoptimistic ,( Int ) ADODB. commandtypeenum. adcmdtable );
Object Missing = System. reflection. Missing. value;
Rsta. addnew (missing, missing );
Rsta. Fields [
0 ]. Value =   27 ;
Rsta. Fields [
1 ]. Value =   " New_dim " ;
Rsta. Update (missing, missing );

//Or use single update from example in my previous post.

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.