How To Check If An Insert Stored Proc Succeeded

Mar 5, 2007

Hi,

How would I check if an insert via stored proc succeeded? Here's the proc I'm using:set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:<Author,,Name>
-- Create date: <Create Date,,>
-- Description:<Description,,>
-- =============================================
ALTER PROCEDURE [dbo].[showtube_addNewSUser]
-- Add the parameters for the stored procedure here
@UserId uniqueidentifier,
@FirstName nvarchar(32),
@LastName nvarchar(32),
@DescShort nvarchar(256),
@DescLong ntext,
@ClanID uniqueidentifier
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;

-- Insert statements for procedure here
Insert into dbo.Users (UserId, FirstName, LastName, DescShort, DescLong, ClanID)
values (@UserId, @FirstName, @LastName, @DescShort, @DescLong, @ClanID);
END



 

 

I tried adding a Return @@RowCount before the END statement, but it always seems to return -1. Could someone tell me what I'm doing wrong? Thanks.

View 3 Replies


ADVERTISEMENT

INSERT In Stored Proc

Jan 10, 2001

given a variable @requestID and @session ID, I need to move requests from
a holding table to the request table using the generated request ID.

In a perfect world...

INSERT INTO Requests(ReqID, field1, field2)
VALUES (SELECT @requestID AS RID, field1, field2
FROM holding WHERE session = '1234')

So that all 5 or so rows from the holding table having a session ID of 1234
get transfered to the request table using the variable value @requestid as
the value satisfying ReqID.

Any ideas?

View 1 Replies View Related

Get A Return Value From An Insert Without Using A Stored Proc.

Oct 31, 2006

hi all, lets say i have this insert command being executed from C# to a SQL Db. //store transaction log
SqlCommand cmdStoreTrans = new SqlCommand("INSERT into Transactions(ImportID,ProfileID,RowID) values (@ImportID,@ProfileID,@RowID);",conn);
cmdStoreTrans.Parameters.Add("@ImportID",importId);
cmdStoreTrans.Parameters.Add("@ProfileID",profileId);
cmdStoreTrans.Parameters.Add("@RowID",i);
try
{
conn.Open();
cmdStoreTrans.ExecuteNonQuery();
conn.Close();
}
catch(SqlException ex)
{
throw(ex);
}I need the new Identity number of that record added.  how can i get that within THIS Sqlcommand.  Currently im closing the connection, creating a new command with 'SELECT MAX(id) from transactions" and getting the value that way, im sure there is a easier way keeping it all within one command object? someone mentioned using something liek @@Identity any help appreciatedTIA, mcm

View 2 Replies View Related

Stored Proc Insert W/look Up Of Value From Other Tabel?

Aug 3, 2004

Hi, I'm fairly new to strored procedures. what I need to do is create a new row with an INSERT specifying value A as a param ( so far no problem ) and value B as a value from table2. Is this possible?
Thanks for your help
Raif

View 3 Replies View Related

Insert Into Stored Proc Problems

Aug 21, 2007

Insert into Stored Proc

--------------------------------------------------------------------------------

I can't seem to get this stored proc to run properly. It won't let me insert records into it. Any suggestions? Can someone tell me if something doesn't look right? I've been over this a million times!

CREATE PROCEDURE TEST_PROC

/*
My Name
*/

AS

BEGIN

SET NOCOUNT ON

DECLARE @MAVG2003 AS MONEY


SET @MAVG2003 = (SELECT AVG(PRICE) AS AVERAGE
FROM ASSESSMENT.DBO.CUSTOMER C WITH (NOLOCK)
LEFT JOIN ASSESSMENT.DBO.ORDER)HEADER OH WITH (NOLOCK)
ON OH.CUSTOMER_ID = C.CUSTOMER_ID
LEFT JOIN ASSESSMENT.DBO.ORDER_DETAIL OD WITH (NOLOCK)
ON OD.ORDER_HEADER_ID = OH.ORDER_HEADER_ID
LEFT JOIN ASSESSMENT.DBO.PRODUCTS P WITH (NOLOCK)
ON P.PRODUCT_ID = OD.PRODUCT_ID
WHERE DATEPART(YYYY, OH.ORDER_DATE) = '2003')



CREATE TABLE #FORECAST(
CUSTOMER_ID INT,
FIRST_NAME VARCHAR(20),
LAST_NAME VARCHAR(20),
TOTAL_2003 MONEY,
FORECAST_2004 MONEY,
FORECAST_2005 MONEY)



INSERT INTO #FORECAST
SELECT C.CUSTOMER_ID,
C.FIRST_NAME,
C.LAST_NAME,
TOTAL_2003 SUM(P.PRICE) AS TOTALYEAR,
0,
0
FROM ASSESSMENT.DBO.CUSTOMER C WITH (NOLOCK)
LEFT JOIN ASSESSMENT.DBO.ORDER)HEADER OH WITH (NOLOCK)
ON OH.CUSTOMER_ID = C.CUSTOMER_ID
LEFT JOIN ASSESSMENT.DBO.ORDER_DETAIL OD WITH (NOLOCK)
ON OD.ORDER_HEADER_ID = OH.ORDER_HEADER_ID
LEFT JOIN ASSESSMENT.DBO.PRODUCTS P WITH (NOLOCK)
ON P.PRODUCT_ID = OD.PRODUCT_ID
WHERE DATEPART(YYYY, OH.ORDER_DATE) = '2003'
GROUP BY C.CUSTOMER_ID



UPDATE #FORECAST
SET FORECAST_2004 = TOTAL_2003 * (TOTAL_2003 / @MAVG2003)

UPDATE #FORECAST
SET FORECAST_2005 = FORECAST_2004 + (FORECAST_2004 * .0105)



SELECT CUSTOMER_ID, TOTAL_2003, FORECAST_2004, FORECAST_2005
FROM #FORECAST
ORDER BY TOTAL_2003 DESC

DROP TABLE #FORECAST


RETURN 0
END

GO

View 12 Replies View Related

SELECT Followed By INSERT All In One Stored Proc

Mar 27, 2008

Hi, i'm an SQL newbie. I'm trying to figure out if there's an easy way to take a single field record set from a SELECT statement and then do an INSERT using that record set, all in one single Stored Procedure.

Here's what i tried to do, but this returns an error "The name "phonenumber" is not permitted in this context. Valid expressions are constants, constant expressions, and (in some contexts) variables. Column names are not permitted.".

The common field in both SELECT and INSERT is phonenumber.

quote:PROCEDURE [dbo].[usp_select_and_insert]

@name varchar(20),

AS

SELECT phonenumber FROM USERLIST where OWNERNAME LIKE @name
INSERT INTO LOGLOG (destination,content) values(phonenumber,'hello world');

GO

Hope that one of you can be kind enough to give me some guidance. Appreciate in advance. :)

View 1 Replies View Related

Bulk Insert Via Stored Proc

May 17, 2008

Hello,

Please consider the following:


CREATE procedure [dbo].[jason_test]

with execute as 'bulk_insert_test_jcb'

as

exec('bulk insert SCORPIO_STAGE_BULK_DATAPDCC from ''\shodbs29CDRDataonmech_stat_apd_clark_credit.dat'' with (formatfile = ''\dixdbs01ScorpioBulkDATAPDCC.fmt'')')



This is a stored proc with execute as a SQL user. It runs one bulk insert. The user bulk_insert_test_jcb does have BulkAdmin rights and if the user is logged in directly to the server, this works fine. If a SQL user is logged in and runs it (a user other than bulk_insert_test_jcb), this also works

However, if I run this as a windows user logged into the server


alter database stage_scorpio_bulk_jcb set trustworthy off

exec jason_test

--Msg 4834, Level 16, State 4, Procedure jason_test, Line 4

--You do not have permission to use the bulk load statement.


I expect this because the server-level permissions (bulk) are stripped off unless the database is trustworthy, so...


alter database stage_scorpio_bulk_jcb set trustworthy on

exec jason_test

--Msg 4861, Level 16, State 1, Procedure jason_test, Line 4

--Cannot bulk load because the file "\shodbs29CDRDataonmech_stat_apd_clark_credit.dat" could not be opened. Operating system error code 5(Access is denied.).


Why does this happen? I thought that, since I'm executing as a SQL user, SQL Server would authenticate over to the server with the datafiles as the service account, but I see the following in the log at SHODBS29


--User Logoff:

-- User Name: ANONYMOUS LOGON

-- Domain: NT AUTHORITY

-- Logon ID: (0x0,0x4C99BD2F)

-- Logon Type: 3

--

--

--For more information, see Help and Support Center at http://go.microsoft.com/fwlink/events.asp.


Any ideas? It seems as if it is still trying to used windows authentication even though the stored proc is supposed to execute as a SQL user.

Someone in another forum said that ownership chaining not being allowed for bulk operations was the problem, but I don't think so, since if I put an "execute as user='bulk_insert_test_jcb'" into the exec string, it still fails with the same issue.


Thanks!
Jason

View 6 Replies View Related

Insert Stored Procedure With Error Check And Transaction Function

Jul 21, 2004

Hi, guys
I try to add some error check and transaction and rollback function on my insert stored procedure but I have an error "Error converting data type varchar to smalldatatime" if i don't use /*error check*/ code, everything went well and insert a row into contract table.
could you correct my code, if you know what is the problem?

thanks

My contract table DDL:
************************************************** ***

create table contract(
contractNum int identity(1,1) primary key,
contractDate smalldatetime not null,
tuition money not null,
studentId char(4) not null foreign key references student (studentId),
contactId int not null foreign key references contact (contactId)
);


My insert stored procedure is:
************************************************** *****

create proc sp_insert_new_contract
( @contractDate[smalldatetime],
@tuition [money],
@studentId[char](4),
@contactId[int])
as

if not exists (select studentid
from student
where studentid = @studentId)
begin
print 'studentid is not a valid id'
return -1
end

if not exists (select contactId
from contact
where contactId = @contactId)
begin
print 'contactid is not a valid id'
return -1
end
begin transaction

insert into contract
([contractDate],
[tuition],
[studentId],
[contactId])
values
(@contractDate,
@tuition,
@studentId,
@contactId)

/*Error Check */
if @@error !=0 or @@rowcount !=1
begin
rollback transaction
print ‘Insert is failed’
return -1
end
print ’New contract has been added’

commit transaction
return 0
go

View 1 Replies View Related

Can You Trace Into A Stored Proc? Also Does RAISERROR Terminate The Stored Proc Execution.

Feb 13, 2008

I am working with a large application and am trying to track down a bug. I believe an error that occurs in the stored procedure isbubbling back up to the application and is causing the application not to run. Don't ask why, but we do not have some of the sourcecode that was used to build the application, so I am not able to trace into the code.
So basically I want to examine the stored procedure. If I run the stored procedure through Query Analyzer, I get the following error message:
Msg 2758, Level 16, State 1, Procedure GetPortalSettings, Line 74RAISERROR could not locate entry for error 60002 in sysmessages.
(1 row(s) affected)
(1 row(s) affected)
I don't know if the error message is sufficient enough to cause the application from not running? Does anyone know? If the RAISERROR occursmdiway through the stored procedure, does the stored procedure terminate execution?
Also, Is there a way to trace into a stored procedure through Query Analyzer?
-------------------------------------------As a side note, below is a small portion of my stored proc where the error is being raised:
SELECT  @PortalPermissionValue = isnull(max(PermissionValue),0)FROM Permission, PermissionType, #GroupsWHERE Permission.ResourceId = @PortalIdAND  Permission.PartyId = #Groups.PartyIdAND Permission.PermissionTypeId = PermissionType.PermissionTypeId
IF @PortalPermissionValue = 0BEGIN RAISERROR (60002, 16, 1) return -3END 
 

View 3 Replies View Related

Stored Proc - Calling A Remote Stored Proc

Aug 24, 2006

I am having trouble executing a stored procedure on a remote server. On my
local server, I have a linked server setup as follows:
Server1.abcd.myserver.comSQLServer2005,1563

This works fine on my local server:

Select * From [Server1.abcd.myserver.comSQLServer2005,1563].DatabaseName.dbo.TableName

This does not work (Attempting to execute a remote stored proc named 'Data_Add':

Exec [Server1.abcd.myserver.comSQLServer2005,1563].DatabaseName.Data_Add 1,'Hello Moto'

When I attempt to run the above, I get the following error:
Could not locate entry in sysdatabases for database 'Server1.abcd.myserver.comSQLServer2005,1563'.
No entry found with that name. Make sure that the name is entered correctly.

Could anyone shed some light on what I need to do to get this to work?

Thanks - Amos.

View 3 Replies View Related

Stored Proc Question : Why If Exisits...Drop...Create Proc?

Jun 15, 2006

Hi All,Quick question, I have always heard it best practice to check for exist, ifso, drop, then create the proc. I just wanted to know why that's a bestpractice. I am trying to put that theory in place at my work, but they areasking for a good reason to do this before actually implementing. All Icould think of was that so when you're creating a proc you won't get anerror if the procedure already exists, but doesn't it also have to do withCompilation and perhaps Execution. Does anyone have a good argument fordoing stored procs this way? All feedback is appreciated.TIA,~CK

View 3 Replies View Related

ASP Cannot Run Stored Proc Until The Web User Has Run The Proc In Query Analyzer

Feb 23, 2007

I have an ASP that has been working fine for several months, but itsuddenly broke. I wonder if windows update has installed some securitypatch that is causing it.The problem is that I am calling a stored procedure via an ASP(classic, not .NET) , but nothing happens. The procedure doesn't work,and I don't get any error messages.I've tried dropping and re-creating the user and permissions, to noavail. If it was a permissions problem, there would be an errormessage. I trace the calls in Profiler, and it has no complaints. Thedatabase is getting the stored proc call.I finally got it to work again, but this is not a viable solution forour production environment:1. response.write the SQL call to the stored procedure from the ASPand copy the text to the clipboard.2. log in to QueryAnalyzer using the same user as used by the ASP.3. paste and run the SQL call to the stored proc in query analyzer.After I have done this, it not only works in Query Analyzer, but thenthe ASP works too. It continues to work, even after I reboot themachine. This is truly bizzare and has us stumped. My hunch is thatwindows update installed something that has created this issue, but Ihave not been able to track it down.

View 1 Replies View Related

Calling A Stored Proc From Within Another Stored Proc

Feb 20, 2003

I have seen this done by viewing code done by a SQL expert and would like to learn this myself. Does anyone have any examples that might help.

I guess I should state my question to the forum !

Is there a way to call a stored proc from within another stored proc?

Thanks In Advance.

Tony

View 1 Replies View Related

Stored Proc Calls Another Stored Proc

Jan 13, 2006

Hi all,

I have a stored procedure "uspX" that calls another stored procedure "uspY" and I need to retrieve the return value from uspY and use it within uspX. Does anyone know the syntax for this?

Thanks for your help!
Cat

View 5 Replies View Related

Calling Stored Proc B From Stored Proc A

Jan 20, 2004

Hi all

I have about 5 stored procedures that, among other things, execute exactly the same SELECT statement

Instead of copying the SELECT statement 5 times, I'd like each stored proc to call a single stored proc that executes the SELECT statement and returns the resultset to the calling stored proc

The SELECT statement in question retrieves a single row from a table containing 10 columns.

Is there a way for a stored proc to call another stored proc and gain access to the resultset of the called stored proc?

I know about stored proc return values and about output parameters, but I think I am looking for something different.

Thanks

View 14 Replies View Related

Calling T SQL Stored Proc From CLR Stored Proc

Aug 30, 2007

I would like to know if the following is possible/permissible:

myCLRstoredproc (or some C# stored proc)
{
//call some T SQL stored procedure spSQL and get the result set here to work with

INSERT INTO #tmpCLR EXECUTE spSQL
}

spSQL
(

INSERT INTO #tmpABC EXECUTE spSQL2
)


spSQL2
(
// some other t-sql stored proc
)


Can we do that? I know that doing this in SQL server would throw (nested EXECUTE not allowed). I dont want to go re-writing the spSQL in C# again, I just want to get whatever spSQL returns and then work with the result set to do row-level computations, thereby avoiding to use cursors in spSQL.

View 2 Replies View Related

Execute Stored Procedure Y Asynchronously From Stored Proc X Using SQL Server 2000

Oct 14, 2007

I am calling a stored procedure (say X) and from that stored procedure (i mean X) i want to call another stored procedure (say Y)asynchoronoulsy. Once stored procedure X is completed then i want to return execution to main program. In background, Stored procedure Y will contiue his work. Please let me know how to do that using SQL Server 2000 and ASP.NET 2.

View 3 Replies View Related

How Can I Call One Or More Stored Procedures Into Perticular One Stored Proc ?

Apr 23, 2008

Hello friends......How are you ? I want to ask you all that how can I do the following ?
I want to now that how many ways are there to do this ?



How can I call one or more stored procedures into perticular one Stored Proc ? in MS SQL Server 2000/05.

View 1 Replies View Related

Check Before INSERT

Aug 6, 2007

I have a pretty standard form that inserts users name, office, and team. It generates a random 10 digit ID for them. How would i got about checking the table to make sure that ID doesn't exist?
Here's my insert code.
        string strConnection = ConfigurationManager.ConnectionStrings["TimeAccountingConnectionString"].ConnectionString;        SqlConnection myConnection = new SqlConnection(strConnection);
        string usercode = GenPassWithCap(9);
        String insertCmd = "INSERT into users (ID, firstname, lastname, office, team) values (@id, @firstname, @lastname, @office, @team)";        SqlCommand myCommand = new SqlCommand(insertCmd, myConnection);
        myCommand.Parameters.Add(new SqlParameter("@id", SqlDbType.VarChar, 10));        myCommand.Parameters["@id"].Value = usercode;
        myCommand.Parameters.Add(new SqlParameter("@firstname", SqlDbType.VarChar, 50));        myCommand.Parameters["@firstname"].Value = txtFirstName.Text;
        myCommand.Parameters.Add(new SqlParameter("@lastname", SqlDbType.VarChar, 50));        myCommand.Parameters["@lastname"].Value = txtLastName.Text;
        myCommand.Parameters.Add(new SqlParameter("@office", SqlDbType.VarChar, 75));        myCommand.Parameters["@office"].Value = dwnOffice.SelectedValue;
        myCommand.Parameters.Add(new SqlParameter("@team", SqlDbType.VarChar, 20));        myCommand.Parameters["@team"].Value = dwnTeam.SelectedValue;
        myCommand.Connection.Open();
            myCommand.ExecuteNonQuery();
 Do I run a completey different select command before hand and try to match that field?

View 1 Replies View Related

Calling A Stored Procedure From Within A Stored Proc

Dec 18, 2007

Hi Peeps
I have a SP that returns xml
I have writen another stored proc in which I want to do something like this:Select FieldOne, FieldTwo, ( exec sp_that_returns_xml ( @a, @b) ), FieldThree from TableName
But it seems that I cant call the proc from within a select.
I have also tried
declare @v xml
set @v = exec sp_that_returns_xml ( @a, @b)
But this again doesn't work
I have tried changing the statements syntax i.e. brackets and no brackets etc...,
The only way Ive got it to work is to create a temp table, insert the result from the xml proc into it and then set @v as a select from the temp table -
Which to be frank is god awful way to do it.
 Any and all help appreciated.
Kal

View 3 Replies View Related

Insert Proc With Both Select And Values

May 18, 2004

I'm trying to write a Stored Proc to Insert records into a table in SQL Server 2000. The fields in the records to be inserted are from another table and from Parameters. I can't seem to figure out the syntax for this.

I created a test in MS Access and it loooks like this:

INSERT INTO PatientTripRegionCountry_Temp ( CountryID, RegionID, Country, PatientTripID )
SELECT Country.CountryID, Country.RegionID, Country.Country, 2 AS PatientTripID
FROM Country

This works great in Access but not in SQL Server. In SQL Server 2 = @PatientTripID

ANY SUGGESTIONS ON HOW TO HANDLE THIS?

View 7 Replies View Related

Check Box Insert Question

Dec 10, 2003

I have 3 tables - Data, Facility and FacilityKey

The FacilityKey table will hold the Data ID and Facility ID based on a series of check boxes on a form.

My question is what is the best way to do the insert into the FacilityKey table from the form? If 5 facilities are checked I don't want to do 5 separate calls to the database for inserts, but I'm a bit confused on what the best method would be.

Thank you!

View 1 Replies View Related

Check Data Before Insert

Aug 15, 2007

I need help thinking about this problem :-)

I have an SSIS pkg that automatically downloads financial extracts from an ftp site. Once the files are downloaded, I load the extract to a table. The table is first deleted before the insert, so that each time the table has "fresh" data (whatever was in the extract for that day).

Once the extract data is in the table, I load the data into yet another table that combines data from many tables. Simple enough.

Problem is, sometimes when I download the extract, it hasn't been updated yet, so I'm downloading an OLD extract. This old data then gets loaded into the first table. That's ok, because it doesn't really hurt anything. I can always delete the table and reload it if necessary.

The problem occurs when the old data goes from this table into the OTHER table. We don't want old data in this other table!

I need a way to check that I'm not loading the same data 2 days in a row into the OTHER table.

I realize that I might be able to solve this problem without using SSIS, but the solutions I've come up with so far aren't 100% satisfactory. I can use a query to check dates and that sort of thing, but it isn't foolproof, and would create problems if I need to manually force the process though, that is, if I need to override the date logic.

Anyways, I'm wondering if there's an SSIS approach to this problem... I can't rely on timestamps on the data files either. They're not accurate.

This is has been very perplexing to me.

Thanks

View 8 Replies View Related

Check For Column &&amp; Insert

Jan 7, 2007

Can you tell me if this is possible? (and how to do it!!)

The application is VS2005, with sql database.

I want to check if a specific column exists in a specific table in the database and if not then add it, all via my application.

I'm happy knowing how to connect to the database & pass sql commands (as I'm doing that anyway to set off backups), but not the actual queries I'd need.

View 3 Replies View Related

Queued Updating - Missing Insert Proc

Oct 17, 2007

Hi

I'm running transactional repl with updateable subscribtions - queued updating. Running SQL 2005 sp2, win 2003 sp1

I have 18 odd subscribers at the moment, my publisher and disttribution is on the same machine with push subscriptions.

The questions I have

nr 1.
While trying to initialize new subscribers I get loads of deadlocks even after I stop dist cleanup agent. This *I think* cause some other unexpected problems.

nr2.
The queue reader would fail saing it cannot find the "insert" proc on the publisher, although it exists.
I have changed anything on the publication so I'm not sure how this happens or why.

nr3.
I replicate a varbinary(max) column and on the odd occasion get the "Length of LOB data" errors which I then set with sp_configure. The catch here is that the length never exceeds a "len()" of 4000, thus the reported LOB and my calculation doesn't tie up.

Help is appreciated.

Thanks




View 3 Replies View Related

Help...pls Check What's Wrong....not Able To Do Insert With Sqldatasource

May 9, 2007

Hi frdz,         I m the new user of ASP.NET WEB APPLICATIONS WITH C# LANGUAGE.         I m using SQL SERVER 2005 and SQLDATASOURCE to get or retrieve the data from the database.         I have created the stored procedure for insert and update.         The stored procedure is executing fine when i m running it from sqlserver2005.         My problem is with the web-application page.         I m not able to insert or update data thru that...         Pls check the code and tell me what's missing out ..........SQLDATASOURCE<asp:SqlDataSource ID="srcemp" runat="server" ConnectionString="<%$ ConnectionStrings:empmaster  %>"     InsertCommand="empStoredProcedure" InsertCommandType="StoredProcedure"     UpdateCommand="empStoredProcedure" UpdateCommandType="StoredProcedure"      DeleteCommand="DELETE FROM empmaster          WHERE empid = @empid" DeleteCommandType="Text"     SelectCommand="select * from empmaster " SelectCommandType="Text">     <InsertParameters><asp:Parameter Name="empname" Type="String" /><asp:Parameter Name="address" Type="String" /><asp:Parameter Name="city"  /><asp:Parameter Name="pincode" /><asp:Parameter Name="state" /></InsertParameters> <UpdateParameters><asp:Parameter Name="empname" Type="String" /><asp:Parameter Name="address" Type="String" /><asp:Parameter Name="city"  /><asp:Parameter Name="pincode" /><asp:Parameter Name="state" /></UpdateParameters>     </asp:SqlDataSource>GRIDVIEW  <asp:GridView ID="empGridView" runat="server" AutoGenerateColumns="False"         DataKeyNames="empid" DataSourceID="srcemp"         Width="56px" >             <Columns>    <asp:TemplateField>    <ItemTemplate>    <asp:LinkButton ID="btnDelete" runat="server" CommandName="Delete" OnClientClick="return confirm('Are you sure you want to delete this row ?');">Delete</asp:LinkButton>    </ItemTemplate>    </asp:TemplateField>                                                  <asp:boundfield datafield="empname"            headertext="emp Name"/>           <asp:boundfield datafield="address"            headertext="Address"/>          <asp:boundfield datafield="city"            headertext="City"/>         <asp:boundfield datafield="state"            headertext="State"/>                                     <asp:CheckBoxField            DataField="deleted"            HeaderText="In Existance" />            </Columns>          </asp:GridView>C# code protected void cmdsubmit_Click(object sender, EventArgs e)    {        srcemp.InsertParameters["empname"].DefaultValue = tbcompanyname.Text;        srcemp.InsertParameters["address"].DefaultValue = tbaddress.Text;         srcemp.InsertParameters["city"].DefaultValue = tbcity.Text;        srcemp.InsertParameters["pincode"].DefaultValue = tbpincode.Text;        srcemp.InsertParameters["state"].DefaultValue = cmbstate.SelectedItem.ToString();         srcemp.Insert();}Note :I m not getting a single error msg for the above code in web-page or stored procedure but it does not insert,update or delete the record from the database....Thanxs in adv...pls reply at earliest if possible...What's missing ??can anyone check out..what's wrong ??

View 1 Replies View Related

How To Check If Sql Insert Command Was Successful

Jan 14, 2008

I'm running a pretty standard insert command on a button (myCommand.ExecuteNonQuery();)
 I have a few other methods that run, but I only want them to proceed if the above was inserted successfully, how would i check that?

View 8 Replies View Related

Performing Insert Query With Check

Feb 29, 2008

hii,,i am using asp.net 2005 and sql server 2005.i have a web page in which i can enter details and it gets stored in a table in a database..in the table thrs a column called as sme_id,,what i want is when one inserts a new sme_id from the page,,it should check in the table so tht no duplicate sme_id wil b generated..,,this code is workin fine,,i just want to implement the above condition...here is the insert code which i have used along with sql datasource:::__________________________
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConflictDetection="CompareAllValues"
ConnectionString="<%$ ConnectionStrings:sme_trackerConnectionString %>"
InsertCommand="INSERT INTO SME_Master(SME_Id, FirstName, LastName, Type_of_SME, Agency_id, Agency_Name, Email, Address, Phone, Mobile, Fax, TimeZone_Id, Experience, City, State, Status, Level_Of_Exam, Other_Comments, Certificate, Expertise)
 VALUES (@SME_Id, @FirstName, @LastName, @Type_of_SME, @Agency_id, @Agency_Name, @Email, @Address, @Phone, @Mobile, @Fax, @TimeZone_Id, @Experience, @City, @State, @Status, @Level_Of_Exam, @Other_Comments, @Certificate, @Expertise)"
OldValuesParameterFormatString="original_{0}" SelectCommand="SELECT * FROM [SME_Master]">
_______hope u got my problem,,,,,reply asap....thnks in advance

View 11 Replies View Related

Query Question - Check Before Insert

Dec 1, 2003

I have a table, emailaddresses with an emailaddress field.

before i do an insert from a stored proc, i want to check if the emailaddress is already in the database.

pseudo-code:

if emailaddresssparameter is IN emailaddress then
do not insert
else
insert into table
end

i've got the insert statement and the stored proc, but how do i write the check to see if it's already there? I mean i could do a select * from emailaddress wehre emailaddress=emailaddressparam

but how to i test it? if the count=1 then skip?

here's my proc now:

ALTER PROCEDURE dbo.AddOneEmailAddress

(
@emailAddress varchar(255),
@emailID int=0 OUTPUT
)

AS
/* SET NOCOUNT ON */
insert into EmailAddresses
(email_address)
values
(@emailAddress)
set @emailID=@@identity

RETURN @@identity

View 2 Replies View Related

SSIS: Check -&&>Update -&&>Insert

Sep 7, 2007

I have two tables from two different Databases

DB1.dbo.Table1 and DB2.dbo.Table2

eX:

Table 1
KEY LName FName Updated
1 GYM ABC Y
1 TIM ABC N
1 PIN ABC N
2 QWE SAD Y
......
....


Table 2
KEY LName FName Updated
1 JIM ABC Y
2 QWE SAM Y

....
....


1) Table 1 and Table 2 are of same structure.
2) In table2, as in above example, few changes have beeen done for KEY1 AND Update =Y, Similarly KEY= 2 AND UPDATED=Y, like for KEY= 1 LName was changed to JIM instead of GYM and for KEY= 2 FName has been changed to SAM instead of SAD.

3) Now I want to do this in SSIS where
a) Its going to process rows of Table2 and check in table1 according to KEY and UPDATE=Y and update the Table1 with Updated = N and Insert that particulra process row of Table2 into Table1

and hence Resultant of Table1 must be like this

Table 1
KEY LName FName Updated
1 GYM ABC N
1 TIM ABC N
1 PIN ABC N
1 JIM ABC Y

2 QWE SAD N
2 QWE SAM Y
......
....

Can somebody help me how to do this in SSIS. Thnaks a lot in advance

View 1 Replies View Related

Package For Update/insert And Check For New Record

Apr 21, 2008

hi,

i'm total newbee on SSIS packages and therefore need guidance.

I want to make a ssis package that (in order):

- check in table (tbl_orders) if there is any new order made
- if new order is made, update column (time_last_change)
- if this order has geography ID (ID_geography) inserted, insert name of geography.

Thank you in advance,

View 2 Replies View Related

The INSERT Statement Conflicted With The CHECK Constraint

Jan 8, 2008

Hi, I am new to MS SQL Server; as I know Access, MYSQL. I made a form though which I want to insert data to SQL SERVER 2005 Database but i during submission I get the below problem, can any one help.


Microsoft OLE DB Provider for ODBC Drivers error '80040e14'

[Microsoft][ODBC SQL Server Driver][SQL Server]The INSERT statement conflicted with the CHECK constraint "SSMA_CC$Bcast$msgHTML$disallow_zero_length". The conflict occurred in database "x485i", table "dbo.Bcast", column 'msgHTML'.

/html/n_.asp, line 193

Best Regards,
Imran

View 3 Replies View Related

Trying To Create A Proc That Will Insert Values Based On A Condition That Is Another Table

Feb 16, 2005

Can someone give me a clue on this. I'm trying to insert values based off of values in another table.

I'm comparing wether two id's (non keys in the db) are the same in two fields (that is the where statement. Based on that I'm inserting into the Results table in the PledgeLastYr collumn a 'Y' (thats what I want to do -- to indicate that they have pledged over the last year).

Two questions

1. As this is set up right now I'm getting NULL values inserted into the PledgeLastYr collumn. I'm sure this is a stupid syntax problem that i'm overlooking but if someone can give me a hint that would be great.

2. How would I go about writing an If / Else statement in T-SQL so that I can have the Insert statement for both the Yes they have pledged and No they have not pledged all in one stored proc. I'm not to familar with the syntax of writing conditional statements within T-SQL as of yet, and if someone can give me some hints on how to do that it would be greatly appriciated.


Thanks in advance, bellow is the code that I have so far:

RB



Select Results.custID, Results.PledgeLastYr
From Results, PledgeInLastYear
Where Results.custID = PledgeInLastYear.constIDPledgeInLastYear
Insert Into Results(PledgeLastYr)
Values ('Y')

View 1 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved