Hi,
I'm writing a VB.NET application who has to insert/update and delete a whole
bunch of records from a File into a Sql Server Database. But I want to be
able to knwo the 'result' of my ctions.
for exemple:
- after an INSERT: knowing if this happened well or not
- after an UPDATE: knowing wich number of records were updated (or if there
were records udpated or not)
- after a DELETE: knwoing the number of deleted recrods.
Is there any possiblity of doing this?
Thanks a lot,
Pieter 9 2874
The return parameter id will tell you the autonumber id created here and if
it executed
/* Stored Procedure Insert tblDocuLijn*/
CREATE PROCEDURE spInserttblDocu Lijn
@ID bigint output,
-- FK tblDocument.DOC ID
@doclDOCID int,
@doclInhoud varchar(2000),
@doclPrijs float
As Insert INTO tblDocuLijn
(doclDOCID,
doclInhoud,
doclPrijs
)
VALUES
(
@doclDOCID,
@doclInhoud,
@doclPrijs
)
SET @ID = SCOPE_IDENTITY( )
GO
for your update you will need a double stored proc
first select @output = count(*) from blabla where your condition
then your update
delete the same
hope it helps
eric
"DraguVaso" <pi**********@h otmail.com> wrote in message
news:%2******** ********@TK2MSF TNGP12.phx.gbl. .. Hi,
I'm writing a VB.NET application who has to insert/update and delete a
whole bunch of records from a File into a Sql Server Database. But I want to be able to knwo the 'result' of my ctions.
for exemple: - after an INSERT: knowing if this happened well or not - after an UPDATE: knowing wich number of records were updated (or if
there were records udpated or not) - after a DELETE: knwoing the number of deleted recrods.
Is there any possiblity of doing this?
Thanks a lot,
Pieter
Check out @@ROWCOUNT and @@ERROR in the BOL.
--
Tom
---------------------------------------------------------------
Thomas A. Moreau, BSc, PhD, MCSE, MCDBA
SQL Server MVP
Columnist, SQL Server Professional
Toronto, ON Canada www.pinnaclepublishing.com/sql
"DraguVaso" <pi**********@h otmail.com> wrote in message
news:%2******** ********@TK2MSF TNGP12.phx.gbl. ..
Hi,
I'm writing a VB.NET application who has to insert/update and delete a whole
bunch of records from a File into a Sql Server Database. But I want to be
able to knwo the 'result' of my ctions.
for exemple:
- after an INSERT: knowing if this happened well or not
- after an UPDATE: knowing wich number of records were updated (or if there
were records udpated or not)
- after a DELETE: knwoing the number of deleted recrods.
Is there any possiblity of doing this?
Thanks a lot,
Pieter
> - after an INSERT: knowing if this happened well or not - after an UPDATE: knowing wich number of records were updated (or if
there were records udpated or not) - after a DELETE: knwoing the number of deleted recrods.
The SqlCommand.Exec uteNonQuery method will return the number of rows
affected by an INSERT, UPDATE or DELETE. If execution fails, a
SqlException is thrown and you can catch it as desired.
--
Hope this helps.
Dan Guzman
SQL Server MVP
"DraguVaso" <pi**********@h otmail.com> wrote in message
news:%2******** ********@TK2MSF TNGP12.phx.gbl. .. Hi,
I'm writing a VB.NET application who has to insert/update and delete a
whole bunch of records from a File into a Sql Server Database. But I want to be able to knwo the 'result' of my ctions.
for exemple: - after an INSERT: knowing if this happened well or not - after an UPDATE: knowing wich number of records were updated (or if
there were records udpated or not) - after a DELETE: knwoing the number of deleted recrods.
Is there any possiblity of doing this?
Thanks a lot,
Pieter
Don't forget that both SQLCommand Objects and SqlDataAdapters have a variety
of events that will let you know all sorts of status of queries etc...
-CJ
"DraguVaso" <pi**********@h otmail.com> wrote in message
news:%2******** ********@TK2MSF TNGP12.phx.gbl. .. Hi,
I'm writing a VB.NET application who has to insert/update and delete a
whole bunch of records from a File into a Sql Server Database. But I want to be able to knwo the 'result' of my ctions.
for exemple: - after an INSERT: knowing if this happened well or not - after an UPDATE: knowing wich number of records were updated (or if
there were records udpated or not) - after a DELETE: knwoing the number of deleted recrods.
Is there any possiblity of doing this?
Thanks a lot,
Pieter
"DraguVaso" <pi**********@h otmail.com> schrieb I'm writing a VB.NET application who has to insert/update and delete a whole bunch of records from a File into a Sql Server Database. But I want to be able to knwo the 'result' of my ctions.
for exemple: - after an INSERT: knowing if this happened well or not - after an UPDATE: knowing wich number of records were updated (or if there were records udpated or not) - after a DELETE: knwoing the number of deleted recrods.
Is there any possiblity of doing this?
The ExecuteNonQuery method is a function returning the number of affected
records.
--
Armin
How to quote and why: http://www.plig.net/nnq/nquote.html http://www.netmeister.org/news/learn2quote.html
When your code calls ExecuteNonQuery to INSERT, UPDATE or DELETE - the
number of rows affected is returned. Here is an example that captures the
number of rows affected into a variable.
Dim recordsAffected As Integer = cmd.ExecuteNonQ uery()
As far as knowing if "things went well" - exceptions will be raised. To
handle exceptions wrap your SQL INSERT, DELETE, and UPDATE calls in a
Try..Catch block and the SqlServerExcept ion class to find out what errors
occurred.
Try
.....
Catch ex as System.Data.Sql Exception
.... handle and/or report error
Finally
.... clean up
End Try
--
Mike
Mike McIntyre
Visual Basic MVP www.getdotnetcode.com
When you call Update
"DraguVaso" <pi**********@h otmail.com> wrote in message
news:%2******** ********@TK2MSF TNGP12.phx.gbl. .. Hi,
I'm writing a VB.NET application who has to insert/update and delete a
whole bunch of records from a File into a Sql Server Database. But I want to be able to knwo the 'result' of my ctions.
for exemple: - after an INSERT: knowing if this happened well or not - after an UPDATE: knowing wich number of records were updated (or if
there were records udpated or not) - after a DELETE: knwoing the number of deleted recrods.
Is there any possiblity of doing this?
Thanks a lot,
Pieter
Hi Pieter,
I find it nice to have my name too in this nice group of people.
If you need more answer, feel free to ask.
Now we wait all for Herfried.
:-)))))
Cor
Thanks guys!! works great!!
"Mike McIntyre [MVP]" <mi****@dotnets howandtell.com> wrote in message
news:uH******** *****@TK2MSFTNG P09.phx.gbl... When your code calls ExecuteNonQuery to INSERT, UPDATE or DELETE - the number of rows affected is returned. Here is an example that captures the number of rows affected into a variable.
Dim recordsAffected As Integer = cmd.ExecuteNonQ uery()
As far as knowing if "things went well" - exceptions will be raised. To handle exceptions wrap your SQL INSERT, DELETE, and UPDATE calls in a Try..Catch block and the SqlServerExcept ion class to find out what errors occurred.
Try .... Catch ex as System.Data.Sql Exception ... handle and/or report error Finally ... clean up End Try
-- Mike
Mike McIntyre Visual Basic MVP www.getdotnetcode.com
When you call Update "DraguVaso" <pi**********@h otmail.com> wrote in message news:%2******** ********@TK2MSF TNGP12.phx.gbl. .. Hi,
I'm writing a VB.NET application who has to insert/update and delete a whole bunch of records from a File into a Sql Server Database. But I want to
be able to knwo the 'result' of my ctions.
for exemple: - after an INSERT: knowing if this happened well or not - after an UPDATE: knowing wich number of records were updated (or if there were records udpated or not) - after a DELETE: knwoing the number of deleted recrods.
Is there any possiblity of doing this?
Thanks a lot,
Pieter
Hehe hi Cor!
It was indeed a nice conference here in this topic with everybody all
together :-)
Pieter
"Cor Ligthert" <no**********@p lanet.nl> wrote in message
news:%2******** ********@TK2MSF TNGP11.phx.gbl. .. Hi Pieter,
I find it nice to have my name too in this nice group of people.
If you need more answer, feel free to ask.
Now we wait all for Herfried.
:-)))))
Cor
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: nomorems |
last post by:
I was trying to copy a range of records from a table to the same table
with a small modification. I was wondering why this takes a long time
compared to just doing a subselect from that table and insert to a new
table (without constraints). Could it be a problem with the constraints
checking capability or the index maintenance? The subselect itself
takes a small time, so that will not be the problem...
Before executing the query I tried...
|
by: Christopher |
last post by:
I AM GETTING A SYSTEM.DATA.SQLCLIENT.SQLEXCEPTION ERROR WHEN ATTEMPTING TO
INSERT DATA INTO A SINGLE TABLE THROUGH A GRID
//If this is due to a spelling error, i will
//inflict a ritual beating upon myself !!!!!!!!!!!!
TABLE SCRIPT
|
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 the necessary
records in it when testing it. I get the error "No value given for one
or more required parameters." when I try to update the database.
Can you tell me what am I doing wrong?
|
by: Primillo |
last post by:
'Full source
'Insert, delete and update don't work
Public Class WebForm1
Inherits System.Web.UI.Page
Protected WithEvents Button1 As
System.Web.UI.WebControls.Button
Protected WithEvents Button2 As
System.Web.UI.WebControls.Button
Protected WithEvents Button3 As
System.Web.UI.WebControls.Button
|
by: alan |
last post by:
in my project there are
5 textbox : tbOrderid, tbSeqNum, tbFoodCode, tbFoodDesc and tbPrice
9 button: btInsert, btdelete, btUpdate, btClear, btBind, btFirst,
btPrevious, btNext and btLast
i cannot do the insert and delete function. Can anybody help me? If
you need the program I can email to anyone who want to help me,
thanks!! ^^Alan
and the code is as follow:
| |
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 textboxes are bound to columns in the dataset.
This works correctly. I have been struggling with
invoking da1.Update(ds1, "tbl1") and with help from the
group here have overcome this obstacle (many thanks for
the help). But I need to be able to Insert...
|
by: abhi81 |
last post by:
Hello All,
I have a table on which I have created a insert,Update and a Delete trigger. All these triggers write a entry to another audit table with the unique key for each table and the timestamp.
Insert and Update trigger work fine when i have only one of them defined.
However when I have all the 3 triggers in place and when i try to fire a insert query on the statement. It triggers both insert and update trigger at the same time and...
|
by: =?Utf-8?B?UmljaA==?= |
last post by:
On a form - I have a datagridview which is docked to the entire form. The
datagridview allows users to Delete and/or Add Rows. On the Form_Load event
I Fill the datagridview source table with a sql DataAdapter (da)
da.SelectCommand.CommandText = "Select * from Servertbl1"
da.Fill(ds, "tbl1")
so far, so good. If I add a row to the datagridview I use the following
sqlDataAdapter code to update the server table - which works OK when...
|
by: magnolia |
last post by:
i created a trigger that will record the changes made to a table .everything works fine except the insert query.whenerever i try to insert a record it fires insert and update triger at the same time which means i hav 2 record for every insert operation.
any help appreciated.
thank u
herez teh code i tried.
ALTER TRIGGER trg_ContactAddress_Audit
ON Address
FOR DELETE, INSERT, UPDATE
AS
|
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| | |