How to insert record into SQL 2k by Insert Statement

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Mullin Yu

    How to insert record into SQL 2k by Insert Statement

    I got object reference not set, is the connection string wrong? Indeed, I
    know int values should be pass to Open() and Execute() method, but don't
    know the parameter variable given by .net.

    Any help?

    // dsn: system dsn
    // database: is the database instance used
    string connectionStrin g = "dsn=ccbsdb;dat abase=testdb";

    String strSQL = "INSERT INTO Outbound (JobID, XMLRequest, DMCUserID,
    SubmissionUserI D, Priority, OutboundType) " +
    "VALUES( 111, 'XML Request', 'DMCUserID', 'SubmissionUser ID', 1, 2 );";

    // Create the command object
    ADODB.Command cmdAdder = new ADODB.CommandCl ass();

    cmdAdder.Active Connection.Open (connectionStri ng, "sa", "ccbs", 1);
    // Start transaction
    cmdAdder.Active Connection.Begi nTrans();
    // Execute the SQL command
    cmdAdder.Comman dText = strSQL;

    object rs = new object();
    object objParam = new Object();

    // Insert into OutboundQueueIt em
    cmdAdder.Execut e(out rs, ref objParam , 1);

    // commit transaction
    cmdAdder.Active Connection.Comm itTrans();


  • Ignacio Machin \( .NET/ C#  MVP \)

    #2
    Re: How to insert record into SQL 2k by Insert Statement

    Hi,

    Do you have any compelling reason to use ADO instead of ADO.NET?

    The error you are getting must be from this line:
    cmdAdder.Active Connection.Open (connectionStri ng, "sa", "ccbs", 1);

    There you are using cmdAdder.Active Connection which is a Connection object
    that you do not init it in the code provided.

    I advise you to use ado.net instead of ado

    Cheers,

    --
    Ignacio Machin,
    ignacio.machin AT dot.state.fl.us
    Florida Department Of Transportation

    "Mullin Yu" <mullin_yu@ctil .com> wrote in message
    news:udr$xWmsDH A.1224@TK2MSFTN GP09.phx.gbl...[color=blue]
    > I got object reference not set, is the connection string wrong? Indeed, I
    > know int values should be pass to Open() and Execute() method, but don't
    > know the parameter variable given by .net.
    >
    > Any help?
    >
    > // dsn: system dsn
    > // database: is the database instance used
    > string connectionStrin g = "dsn=ccbsdb;dat abase=testdb";
    >
    > String strSQL = "INSERT INTO Outbound (JobID, XMLRequest, DMCUserID,
    > SubmissionUserI D, Priority, OutboundType) " +
    > "VALUES( 111, 'XML Request', 'DMCUserID', 'SubmissionUser ID', 1, 2 );";
    >
    > // Create the command object
    > ADODB.Command cmdAdder = new ADODB.CommandCl ass();
    >
    > cmdAdder.Active Connection.Open (connectionStri ng, "sa", "ccbs", 1);
    > // Start transaction
    > cmdAdder.Active Connection.Begi nTrans();
    > // Execute the SQL command
    > cmdAdder.Comman dText = strSQL;
    >
    > object rs = new object();
    > object objParam = new Object();
    >
    > // Insert into OutboundQueueIt em
    > cmdAdder.Execut e(out rs, ref objParam , 1);
    >
    > // commit transaction
    > cmdAdder.Active Connection.Comm itTrans();
    >
    >[/color]


    Comment

    • Mullin Yu

      #3
      Re: How to insert record into SQL 2k by Insert Statement

      how can i use ADO.NET?

      i just add ADODB, and i think i'm using ADO.NET!!!

      thanks!

      "Ignacio Machin ( .NET/ C# MVP )" <ignacio.mach in AT dot.state.fl.us > wrote
      in message news:%23q2EaUps DHA.1876@TK2MSF TNGP09.phx.gbl. ..[color=blue]
      > Hi,
      >
      > Do you have any compelling reason to use ADO instead of ADO.NET?
      >
      > The error you are getting must be from this line:
      > cmdAdder.Active Connection.Open (connectionStri ng, "sa", "ccbs", 1);
      >
      > There you are using cmdAdder.Active Connection which is a Connection object
      > that you do not init it in the code provided.
      >
      > I advise you to use ado.net instead of ado
      >
      > Cheers,
      >
      > --
      > Ignacio Machin,
      > ignacio.machin AT dot.state.fl.us
      > Florida Department Of Transportation
      >
      > "Mullin Yu" <mullin_yu@ctil .com> wrote in message
      > news:udr$xWmsDH A.1224@TK2MSFTN GP09.phx.gbl...[color=green]
      > > I got object reference not set, is the connection string wrong? Indeed,[/color][/color]
      I[color=blue][color=green]
      > > know int values should be pass to Open() and Execute() method, but don't
      > > know the parameter variable given by .net.
      > >
      > > Any help?
      > >
      > > // dsn: system dsn
      > > // database: is the database instance used
      > > string connectionStrin g = "dsn=ccbsdb;dat abase=testdb";
      > >
      > > String strSQL = "INSERT INTO Outbound (JobID, XMLRequest, DMCUserID,
      > > SubmissionUserI D, Priority, OutboundType) " +
      > > "VALUES( 111, 'XML Request', 'DMCUserID', 'SubmissionUser ID', 1, 2 );";
      > >
      > > // Create the command object
      > > ADODB.Command cmdAdder = new ADODB.CommandCl ass();
      > >
      > > cmdAdder.Active Connection.Open (connectionStri ng, "sa", "ccbs", 1);
      > > // Start transaction
      > > cmdAdder.Active Connection.Begi nTrans();
      > > // Execute the SQL command
      > > cmdAdder.Comman dText = strSQL;
      > >
      > > object rs = new object();
      > > object objParam = new Object();
      > >
      > > // Insert into OutboundQueueIt em
      > > cmdAdder.Execut e(out rs, ref objParam , 1);
      > >
      > > // commit transaction
      > > cmdAdder.Active Connection.Comm itTrans();
      > >
      > >[/color]
      >
      >[/color]


      Comment

      Working...