How to insert record into SQL 2k by Insert Statement

  • Thread starter Thread starter Mullin Yu
  • Start date Start date
M

Mullin Yu

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 connectionString = "dsn=ccbsdb;database=testdb";

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

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

cmdAdder.ActiveConnection.Open(connectionString, "sa", "ccbs", 1);
// Start transaction
cmdAdder.ActiveConnection.BeginTrans();
// Execute the SQL command
cmdAdder.CommandText = strSQL;

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

// Insert into OutboundQueueItem
cmdAdder.Execute(out rs, ref objParam , 1);

// commit transaction
cmdAdder.ActiveConnection.CommitTrans();
 
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.ActiveConnection.Open(connectionString, "sa", "ccbs", 1);

There you are using cmdAdder.ActiveConnection 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,
 
Back
Top