473,382 Members | 1,665 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

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 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
2 1989
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: PT | last post by:
I got a problem. And thats..... First of all, I got these three tables. ------------------- ------------------ ---------------------- tblPerson tblPersonSoftware ...
1
by: Thomas Bartkus | last post by:
The meaning of REPLACE INTO is clear to me. IF the new record presents new key values, then it is inserted as a new record. IF the new record has key values that match a pre-existing record, then...
6
by: Karen Middleton | last post by:
In MS Access I can do in one SQL statement a update if exists else a insert. Assuming my source staging table is called - SOURCE and my target table is called - DEST and both of them have the...
14
by: serge | last post by:
I have a scenario where two tables are in a One-to-Many relationship and I need to move the data from the Many table to the One table so that it becomes a One-to-One relationship. I need to...
16
by: Philip Boonzaaier | last post by:
I want to be able to generate SQL statements that will go through a list of data, effectively row by row, enquire on the database if this exists in the selected table- If it exists, then the colums...
1
by: ms | last post by:
I am running an insert statement from a dbf file and there is one record causing the insert to fail. A msg. is returned stating it is due to an invalid datatype. There are 2 text fields, 2...
3
by: celineusa | last post by:
Hello! Here is part of my database: tblStudents: StudentID tblMajorsAndStudents: StudentID, MajorID tblMajors: MajorID tblMajorsAndClasses: MajorID, ClassID, QuarterTaken tblClasses:...
10
by: Mike | last post by:
I know this sounds strange but I am at a loss. I am calling a simple funtion that opens a connection to a SQL Server 2000 database and executes an Insert Statement. private void...
4
by: Mike Hnatt | last post by:
My goal is to get data from an XML file into a couple of tables in an Access database. The XML file is a little complex so I need control over what I do (I can't just read it into a dataset). ...
6
by: rn5a | last post by:
During registration, users are supposed to enter the following details: First Name, Last Name, EMail, UserName, Password, Confirm Password, Address, City, State, Country, Zip & Phone Number. I am...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.