By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,647 Members | 1,604 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,647 IT Pros & Developers. It's quick & easy.

How to insert record into SQL 2k by Insert Statement

P: n/a
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();
Nov 15 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
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,

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

"Mullin Yu" <mu*******@ctil.com> wrote in message
news:ud**************@TK2MSFTNGP09.phx.gbl...
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();

Nov 15 '05 #2

P: n/a
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.machin AT dot.state.fl.us> wrote
in message news:%2****************@TK2MSFTNGP09.phx.gbl...
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,

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

"Mullin Yu" <mu*******@ctil.com> wrote in message
news:ud**************@TK2MSFTNGP09.phx.gbl...
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();


Nov 15 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.