i have a Access DB table there is only one row allowed so if no row exist it shouls create one else it should just update it. What should i put in the if statement? -
if ()
-
{
-
int i = 1;
-
string UpdateStr = "Insert into qx_Company " +
-
"(AST__ID, AST__NAME, AST__STREET, AST__TOWN, AST__CITY, AST__TEL, AST__FAX, AST__MAIL, AST__SITE, AST__POST )" +
-
"values(" +i.ToString()+ ",'"+ txtComp_Name.Text +"','"+ txtComp_Street.Text + "','"+ txtComp_Town.Text +"','"+ txtComp_City.Text +"','"+ txtComp_Tel.Text +"','"+ txtComp_Fax.Text + "','"+ txtComp_Email.Text +"','"+ txtComp_Website.Text +"',"+ txtComp_Box.Text +")";
-
-
}else{
-
string UpdateStr = "UPDATE qx_Company SET AST__NAME = '" + txtComp_Name.Text +"', " +
-
" AST__STREET = '" + txtComp_Street.Text + "', " +
-
" AST__TOWN = '" + txtComp_Town.Text + "', " +
-
" AST__CITY = '" + txtComp_City.Text + "', " +
-
" AST__TEL = '" + txtComp_Tel.Text + "', " +
-
" AST__FAX = '" + txtComp_Fax.Text + "', " +
-
" AST__MAIL = '" + txtComp_Email.Text + "', " +
-
" AST__SITE = '" + txtComp_Website.Text +"', " +
-
" AST__POST = '" + txtComp_Box.Text + "', " +
-
-
}
-
1 3583
First you get no.of records from the table and use the count in the if condition.
Eg: -
string Query= "select count(*) from qx_Company"
-
SqlCommand cmd=new SqlCommand(---)
-
cmd.CommandText(Query);
-
int count=Convert.ToInt32(cmd.ExecuteScalar());
-
if(count=0)
-
{
-
//Your insert code
-
}
-
else
-
{
-
//Your update code
-
}
-
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
by: shottarum |
last post by:
I currently have 2 tables as follows:
CREATE TABLE .
(
mhan8 int,
mhac02 varchar(5),
mhmot varchar(5),
mhupmj int
)
|
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...
|
by: robert |
last post by:
been ruminating on the question (mostly in a 390/v7 context) of
whether, and if so when, a row update becomes an insert/delete.
i assume that there is a threshold on the number of columns of
the...
|
by: Suler Abou |
last post by:
Hi,
I'm having a problem with an SQL statement, I have a statement that goes
like this:
"INSERT INTO table VALUES('TransID','CID',etc...);"
it basically adds new data to a table. When the...
|
by: Shapper |
last post by:
Hello,
I have created 3 functions to insert, update and delete an Access
database record. The Insert and the Delete code are working fine.
The update is not. I checked and my database has all...
|
by: Tom Allison |
last post by:
I seemed to remember being able to do this but I can't find the docs.
Can I run a sql query to insert new or update existing rows in one query?
Otherwise I have to run a select query to see if...
|
by: anachronic_individual |
last post by:
Hi all,
Is there a standard library function to insert an array of characters
at a particular point in a text stream without overwriting the existing
content, such that the following data in...
|
by: djsdaddy |
last post by:
Good Day All, I have some EEO data in an old dBase4 database that I have converted to an Access table. Since dBase was not a relational database, I didn't create any key fields. I linked all of the...
|
by: Dilruba |
last post by:
asp, vbscript, Ms Access
I am using vbscript to insert & update ms accees.
Insert operation is working , but update operation is not working.
I have used the following codes:
...
|
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,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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$) {
}
...
|
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...
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
| | |