473,394 Members | 1,870 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,394 software developers and data experts.

How to execute an INSERT and UPDATE SQL commands from inside a CSharp program

How do I have to code the execution of such an INSERT or UPDATE SQL statement ?

Given the follwoing code:

command = connection.CreateCommand();
command.CommandText = "INSERT ....";

A SELECT statement would continue with:

OracleDataReader rdr;

rdr = commnad.ExecuteReader();

But this doesn't work for INSERT and UPDATE commands.

How should I proceed in this case ?

Robert

Jun 11 '07 #1
3 5759
On Jun 11, 11:20 am, r...@lucent.com (Robert McCabe) wrote:
How do I have to code the execution of such an INSERT or UPDATE SQL statement ?

Given the follwoing code:

command = connection.CreateCommand();
command.CommandText = "INSERT ....";

A SELECT statement would continue with:

OracleDataReader rdr;

rdr = commnad.ExecuteReader();

But this doesn't work for INSERT and UPDATE commands.

How should I proceed in this case ?

Robert
You just asked the same question someone asked just before you, and
was answered.

Jun 11 '07 #2
On Jun 11, 8:23 pm, z...@construction-imaging.com wrote:
On Jun 11, 11:20 am, r...@lucent.com (Robert McCabe) wrote:


How do I have to code the execution of such an INSERT or UPDATE SQL statement ?
Given the follwoing code:
command = connection.CreateCommand();
command.CommandText = "INSERT ....";
A SELECT statement would continue with:
OracleDataReader rdr;
rdr = commnad.ExecuteReader();
But this doesn't work for INSERT and UPDATE commands.
How should I proceed in this case ?
Robert

You just asked the same question someone asked just before you, and
was answered.- Hide quoted text -

- Show quoted text -
Try this:

private void InsertRecord(string nonQuery)
{
SqlConnection connectionObj = new SqlConnection();
SqlCommand command = new SqlCommand();
command.Connection = connectionObj;
command.Connection.ConnectionString =
ConfigurationManager.AppSettings["DBConnectionString"];//Specify your
connection string here
command.CommandText = nonQuery;
command.Connection.Open();

try
{
command.ExecuteNonQuery();
}
finally
{
command.Connection.Close();
}
}

Jun 11 '07 #3
On Jun 11, 8:39 pm, "Aneesh Pulukkul[MCSD.Net]" <anees...@gmail.com>
wrote:
On Jun 11, 8:23 pm, z...@construction-imaging.com wrote:
On Jun 11, 11:20 am, r...@lucent.com (Robert McCabe) wrote:
How do I have to code the execution of such an INSERT or UPDATE SQL statement ?
Given the follwoing code:
command = connection.CreateCommand();
command.CommandText = "INSERT ....";
A SELECT statement would continue with:
OracleDataReader rdr;
rdr = commnad.ExecuteReader();
But this doesn't work for INSERT and UPDATE commands.
How should I proceed in this case ?
Robert
You just asked the same question someone asked just before you, and
was answered.- Hide quoted text -
- Show quoted text -

Try this:

private void InsertRecord(string nonQuery)
{
SqlConnection connectionObj = new SqlConnection();
SqlCommand command = new SqlCommand();
command.Connection = connectionObj;
command.Connection.ConnectionString =
ConfigurationManager.AppSettings["DBConnectionString"];//Specify your
connection string here
command.CommandText = nonQuery;
command.Connection.Open();

try
{
command.ExecuteNonQuery();
}
finally
{
command.Connection.Close();
}
}
You can also use Dataset, with TableAdapter. In this way all
coonections are made automatically, and you can define your own
methods. If you are intereseted in I will explain you.
Jun 12 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Sheila King | last post by:
I have searched for an answer to this question on the comp.lang.python archives at Google Groups, and also looked through the (sparse) MySQLdb documentation, and cannot confirm for a FACT what I...
4
by: Joel Thornton | last post by:
Whenever something is inserted to a given table, I want to run some shell commands using xp_cmdshell. Would it be a bad idea to put this xp_cmdshell in the INSERT trigger of this table? I...
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...
4
by: Chris | last post by:
I posted this in the C# language group, then thought it might be more appropriate in this group. I would not cross-post except I want the answer so badly. I built small C# Web and Web Service...
2
by: Rich | last post by:
Hello, I have an oleDBDataAdapter (da1) which gets data from an Access mdb and fills a dataset (ds1) with integer data from "tbl1" in Access. Data displays in textboxes on a form. The...
3
by: Scott Emick | last post by:
I've been trying for some time now to decrypt with GPG from inside vb .net to no avail. my normal decrypt command goes something like this: gpg.exe --armor --passphrase-fd 0 <...
3
by: Nexus | last post by:
I have created a program in Visual Basic that creates CSV file on the PC. However I need to do an upload of these files into DB2 tables (from time to time) I'm currently using ADO to create a...
0
by: mwenz | last post by:
I am trying to update an Access table using OLEDB in VB.Net 2005. I can add rows but I cannot update them. Code to instantiate the Access database and table... Dim conn As New...
13
by: Terry Olsen | last post by:
I'm using OleDb to connect with an Access Database. I have anywhere from 10 to over 100 records that I need to either INSERT if the PK doesn't exist or UPDATE if the PK does exist, all in a single...
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.