Update Stored Procedure Not Updating

Apr 12, 2008

Hello,
I'm working on a grant management database for a project in my databases class and I'm having some issues updating grants into the database.
Here is my situation:
How this page works is, it gets a query string from a search_grant.aspx page.  In this query string, it gets the grant ID of the grant the user wants to edit.  If the grant id is a valid grant, it then, upon page_load in C#:
1.) Creates an Sql connection set to a viewGrant stored procedure,
2.) Adds in all the necessary parameters as output variables
3.) Sets private members declared inside of the partial class to those values it gets from the stored procedure
4.) Sets textbox controls on the page to those values
5.) Displays the page with all the populated data from the stored procedure

That part works fine.  I was having an issue where clicking the update button would not grab the new values that the user input into the textboxes.  I later realized that the Page_Load code was being re-executed BEFORE the button was being clicked (kind of dumb but...whatever).  To fix it, I placed all of the code to do the above statements inside of a:
if (!Page.IsPostBack)
{
// Do code here
}
That works fine.  The problem, however, is that it's STILL not updating.  The stored procedure works just fine inside of the management studio, but not in the ASP Page.  The code is similar to that of my new_grant.aspx page, which creates a grant into the database.  Why that works and this doesn't, I don't know.  Even when I hard code the values into the parameters in C#, it's not updating the data!  There are no errors that are being returned, so this has really boggled my mind.
Any help is greatly appreciated!

Here is some sample code of what I'm doing:protected void Update_button_Click(object sender, EventArgs e)
{
// Create SQL connection to update Grant
string ConnectionString = "connection string which works fine";
SqlConnection sqlConnection2 = new SqlConnection();

try
{
sqlConnection2.ConnectionString = ConnectionString;
sqlConnection2.Open();
}
catch (Exception Ex)
{
if (sqlConnection2 != null) { sqlConnection2.Dispose(); }

SQLErrorLabel.Text = Ex.Message;
SQLErrorLabel.Visible = true;
return;
}

// ------------------ Update values into database -------------------


// Create the statement to use on the database
SqlCommand editGrant = new SqlCommand("editGrant", sqlConnection2);
editGrant.CommandType = CommandType.StoredProcedure;
editGrant.Connection = sqlConnection2;


// Set our values for each variable
GrantName = GrantName_input.Text;
ProjectDescription = ProjDesBox.Text;
ReportingYear = Int32.Parse(ReportYearBox.SelectedItem.ToString());
ActivityStarted = Activity_Date.Text;
DateSubmitted = Date_Submitted.Text;
Audit = chkAudit.Checked;
TypeID = Type_ID_input.SelectedValue;
FunderID = Funder_List.SelectedValue;
StatusID = Status_ID_input.SelectedValue;
AcademicDepartmentID = AcademicID_List.SelectedValue;
PIID = PI_List.SelectedValue;
ContractNumber = txtContractNum.Text;
ESUAccountNumber = txtESUAccountNum.Text;
AmountAwarded = txtAmount.Text;
AwardDate = Award_Date.Text;
DateContractSigned = txtDateSigned.Text;
ReportingNotes = ReportingNotesbox.Text;
NotesNotes = GrantNotesbox.Text;

string ReportingTimestamp = DateTime.Now.ToString();
string ReportingWho = Membership.GetUser().ToString();
string NotesTimestamp = DateTime.Now.ToString();
string NotesWho = Membership.GetUser().ToString();

#region insertParams
// Add our parameters that SQL will be using
editGrant.Parameters.AddWithValue("@GrantID", GID);
editGrant.Parameters["@GrantID"].Direction = ParameterDirection.Input;

editGrant.Parameters.AddWithValue("@GrantName", GrantName);
editGrant.Parameters["@GrantName"].Direction = ParameterDirection.Input;

editGrant.Parameters.AddWithValue("@ProjectDescription", ProjectDescription);
editGrant.Parameters["@ProjectDescription"].Direction = ParameterDirection.Input;

editGrant.Parameters.AddWithValue("@ReportingYear", ReportingYear);
editGrant.Parameters["@ReportingYear"].Direction = ParameterDirection.Input;

editGrant.Parameters.AddWithValue("@ActivityStarted", ActivityStarted);
editGrant.Parameters["@ActivityStarted"].Direction = ParameterDirection.Input;

editGrant.Parameters.AddWithValue("@DateSubmitted", DateSubmitted);
editGrant.Parameters["@DateSubmitted"].Direction = ParameterDirection.Input;

editGrant.Parameters.AddWithValue("@Audit", Audit);
editGrant.Parameters["@Audit"].Direction = ParameterDirection.Input;

editGrant.Parameters.AddWithValue("@TypeID", TypeID);
editGrant.Parameters["@TypeID"].Direction = ParameterDirection.Input;

editGrant.Parameters.AddWithValue("@StatusID", StatusID);
editGrant.Parameters["@StatusID"].Direction = ParameterDirection.Input;

editGrant.Parameters.AddWithValue("@FunderID", FunderID);
editGrant.Parameters["@FunderID"].Direction = ParameterDirection.Input;

editGrant.Parameters.AddWithValue("@AcademicDepartmentID", AcademicDepartmentID);
editGrant.Parameters["@AcademicDepartmentID"].Direction = ParameterDirection.Input;

editGrant.Parameters.AddWithValue("@PIID", PIID);
editGrant.Parameters["@PIID"].Direction = ParameterDirection.Input;

editGrant.Parameters.AddWithValue("@ContractNumber", ContractNumber);
editGrant.Parameters["@ContractNumber"].Direction = ParameterDirection.Input;

editGrant.Parameters.AddWithValue("@ESUAccountNumber", ESUAccountNumber);
editGrant.Parameters["@ESUAccountNumber"].Direction = ParameterDirection.Input;

editGrant.Parameters.AddWithValue("@AmountAwarded", AmountAwarded);
editGrant.Parameters["@AmountAwarded"].Direction = ParameterDirection.Input;

editGrant.Parameters.AddWithValue("@AwardDate", AwardDate);
editGrant.Parameters["@AwardDate"].Direction = ParameterDirection.Input;

editGrant.Parameters.AddWithValue("@DateContractSigned", DateContractSigned);
editGrant.Parameters["@DateContractSigned"].Direction = ParameterDirection.Input;

editGrant.Parameters.AddWithValue("@ReportingNotes", ReportingNotes);
editGrant.Parameters["@ReportingNotes"].Direction = ParameterDirection.Input;

editGrant.Parameters.AddWithValue("@ReportingTimestamp", ReportingTimestamp);
editGrant.Parameters["@ReportingTimestamp"].Direction = ParameterDirection.Input;

editGrant.Parameters.AddWithValue("@ReportingWho", ReportingWho);
editGrant.Parameters["@ReportingWho"].Direction = ParameterDirection.Input;

editGrant.Parameters.AddWithValue("@NotesNotes", NotesNotes);
editGrant.Parameters["@NotesNotes"].Direction = ParameterDirection.Input;

editGrant.Parameters.AddWithValue("@NotesTimestamp", NotesTimestamp);
editGrant.Parameters["@NotesTimestamp"].Direction = ParameterDirection.Input;

editGrant.Parameters.AddWithValue("@NotesWho", NotesWho);
editGrant.Parameters["@NotesWho"].Direction = ParameterDirection.Input;
#endregion

// Execute the UPDATE statement to Grant
editGrant.ExecuteNonQuery();
sqlConnection2.Close();
sqlConnection2.Dispose();

Response.Redirect("editedGrant.aspx?id=" + GrantIDBox.Text);
}EDIT: Problem Solved! Problem was the that the GrantID wasn't being properly set.

View 6 Replies


ADVERTISEMENT

Updating A Value In A Stored Procedure

Dec 12, 2007

I have a batch input system consisting of two tables which I've simplified below.
 
(Batch Table)BatchID   IntBatchTotal  Decimal(18.2)
(BatchTran Table)BatchTranID  IntBatchTranHeaderID Int   This links to BatchID BatchTranValue  Decimal(18.2)BatchTranAccountNo Int
 
When the batch is complete I want to move the details from the Batch files and transfer them to the relevant Accounts files.
 
(Account Table)AccountNoID  IntAccountTotal  Decimal(18.2)
(AccountTran Table)AccountTranBatchID IntAccountTranBatchRef IntAccountTranAmount Decimal(18.2)
 
I want to be able to run a stored procedure which selects all Batches and Transactions with a reference passed to the stored procedure (@BatchID) and create the entries in the AccountTran Table
 INSERT INTO AccountTran(AccountTranBatchID, AccountTranBatchRef, AccountTranAmount) SELECT  BatchTranId, BatchTranHeaderID, BatchTranValue FROM BatchTran WHERE BatchTranHeaderID=@BatchID
No problems so far, the details are created perfectly.
 
What I want to do next is to take the values in BatchTranValue (which have been passed into AccountTranAmount) and add it to AccountTotal field
My question is can this be completed in one stored procedure if so can you guide me as to how I achieve this?
 
Many thanks

View 3 Replies View Related

Stored Procedure Not Updating

Jun 5, 2006

Using VS.Net 2003 and C#
Why won't this update the table?
public bool changeVisibility( string Id, bool visibility )
{
using( SqlConnection conn = new SqlConnection( @SQLHelper.CONN_STRING ) )
{
using( SqlCommand command = new SqlCommand( "changeVisibility", conn ) )
{
command.CommandType = CommandType.StoredProcedure;
command.Parameters.Add( "@Id", Id );
command.Parameters.Add( "@visibility", visibility );
<snip>
And then the stored procedure:
CREATE PROCEDURE dbo.changeVisibility
 @Id           VARCHAR(20),  @visibility         BIT
 ASBEGIN BEGIN TRAN      UPDATE courseStructure  SET    visible = @visibility                       WHERE  Id = @Id  
 COMMIT TRAN
 ENDGO
The @visibility seems to be the problem.
I set it in the code as boolean.  And it goes into the sp as a BIT.
This should work but doesn't.
If I change the SET visible = 0 it works ok, but not with @visibility.
Thanks,
Zath

View 4 Replies View Related

Updating A View Through A Stored Procedure.

Oct 14, 2007

Hi i have a page in which a user fills out info on a page, the problem i am getting is that when the save button is clicked all text box values apart from one are saving to the database this field is the "constructor_ID" field. The save button performs a stored procedure, however there is a view which is doing something as well, would it be possible to write a stored procedure which would update the view at the same time?
CREATE PROCEDURE sp_SurveyMainDetails_Update
@Constructor_ID  int,@SurveyorName_ID int,@Survey_Date char(10),@Survey_Time char (10),@AbortiveCall bit,@Notes  text,@Survey_ID int,@User_ID int,@Tstamp timestamp out AS
 
DECLARE @CHANGED_Tstamp timestampDECLARE @ActionDone char(6)SET @ActionDone = 'Insert'
SET @CHANGED_Tstamp = (SELECT Tstamp FROM tblSurvey WHERE Survey_ID = @Survey_ID)IF @Tstamp <> @CHANGED_Tstamp --AND @@ROWCOUNT =0 BEGIN  SET @Tstamp =  @CHANGED_Tstamp  RAISERROR('This survey has already been updated since you opened this record',16,1)  RETURN 14 ENDELSE
   BEGIN
SELECT * FROM tblSurvey WHERE  Constructor_ID   = @Constructor_ID   AND  --Contractor_ID  = @Contractor_ID  AND  Survey_DateTime = Convert(DateTime,@Survey_Date + ' ' + LTRIM(RTRIM(@Survey_Time)), 103) AND  IsAbortiveCall = @AbortiveCall     IF @@ROWCOUNT>0                          SET @ActionDone = 'Update'
UPDATE tblSurvey SET    Constructor_ID   = @Constructor_ID   ,  SurveyorName_ID   = @SurveyorName_ID ,     Survey_DateTime = Convert(DateTime,@Survey_Date + ' ' + LTRIM(RTRIM(@Survey_Time)), 103) ,  IsAbortiveCall = @AbortiveCall ,  Note  = @Notes               WHERE Survey_ID = @Survey_ID AND Tstamp = @Tstamp IF @@error = 0 begin                        exec dhoc_ChangeLog_Insert    'tblSurvey',  @Survey_ID,  @User_ID,  @ActionDone,  'Main Details',  @Survey_ID
    end else BEGIN  RAISERROR ('The request has not been proessed, it might have been modifieid since you last opened it, please try again',16,1)  RETURN 10   END SELECT * FROM tblSurvey WHERE Survey_ID=@Survey_ID     
END
--Make sure this has saved, if not return 10 as this is unexpected error
--SELECT * FROM tblSurvey
DECLARE @RETURN_VALUE tinyintIF @@error <>0 RETURN @@errorGO
 This is the view;
CREATE VIEW dbo.vw_Property_FetchASSELECT     dbo.tblPropertyPeriod.Property_Period, dbo.tblPropertyType.Property_Type, dbo.tblPropertyYear.Property_Year, dbo.tblProperty.Add1,                       dbo.tblProperty.Add2, dbo.tblProperty.Add3, dbo.tblProperty.Town, dbo.tblProperty.PostCode, dbo.tblProperty.Block_Code, dbo.tblProperty.Estate_Code,                       dbo.tblProperty.UPRN, dbo.tblProperty.Tstamp, dbo.tblProperty.Property_ID, dbo.tblProperty.PropertyStatus_ID, dbo.tblProperty.PropertyType_ID,                       dbo.tblProperty.Correspondence_Add4, dbo.tblProperty.Correspondence_Add3, dbo.tblProperty.Correspondence_Add2,                       dbo.tblProperty.Correspondence_Add1, dbo.tblProperty.Correspondence_Phone, dbo.tblProperty.Correspondence_Name,                       dbo.tblPropertyStatus.Property_Status, dbo.tblProperty.Floor_Num, dbo.tblProperty.Num_Beds, dbo.vw_LastSurveyDate.Last_Survey_Date,                       dbo.tblProperty_Year_Period.Constructor_ID, dbo.tblProperty_Year_Period.PropertyPeriod_ID, dbo.tblProperty_Year_Period.PropertyYear_ID,                       LTRIM(RTRIM(ISNULL(dbo.tblProperty.Add1, ''))) + ', ' + LTRIM(RTRIM(ISNULL(dbo.tblProperty.Add2, '')))                       + ', ' + LTRIM(RTRIM(ISNULL(dbo.tblProperty.Add3, ''))) + ', ' + LTRIM(RTRIM(ISNULL(dbo.tblProperty.PostCode, ''))) AS Address,                       dbo.tblProperty.TenureFROM         dbo.tblPropertyType RIGHT OUTER JOIN                      dbo.tblProperty LEFT OUTER JOIN                      dbo.tblProperty_Year_Period ON dbo.tblProperty.Property_ID = dbo.tblProperty_Year_Period.Property_ID LEFT OUTER JOIN                      dbo.vw_LastSurveyDate ON dbo.tblProperty.Property_ID = dbo.vw_LastSurveyDate.Property_ID LEFT OUTER JOIN                      dbo.tblPropertyStatus ON dbo.tblProperty.Status_ID = dbo.tblPropertyStatus.PropertyStatus_ID ON                       dbo.tblPropertyType.PropertyType_ID = dbo.tblProperty.PropertyType_ID LEFT OUTER JOIN                      dbo.tblPropertyPeriod ON dbo.tblProperty.PropertyPeriod_ID = dbo.tblPropertyPeriod.PropertyPeriod_ID LEFT OUTER JOIN                      dbo.tblPropertyYear ON dbo.tblProperty.PropertyYear_ID = dbo.tblPropertyYear.PropertyYear_ID
   
 

View 1 Replies View Related

Stored Procedure For Updating A Table

Jul 10, 2013

I have a table Patient_Registration with columns Patient_ID,Registration_Date,RENEWAL_DATE_D

After billing This table will get updated every time , when there is any new patient registered or any old patient got renewed there account.

For New patient registration the service code is 1.
and for renewed patient the service code is 293.

CREATE PROCEDURE [dbo].[SP_UPDATE_PATIENT_REGISTRATION_RENEW_DATE]
@PID BIGINT
AS
BEGIN
UPDATE PATIENT_REGISTRATION SET RENEWAL_DATE_D = (SELECT top 1 BD.BILL_DATE_D

[Code] .....

View 3 Replies View Related

Stored Procedure For Updating Bit Datatype Column

Mar 25, 2008

Hi guys,
I have a table with following columns and records.
Empid       Empname        Phone     Flag
14             Rajan                 2143          116             Balan                 4321          122             Nalini                 3456          023             Ganesh              9543          0
Now i need to create a stored procedure which will convert the flag values to vice versa since it is a bit datatype. That is if execute the stored procedure it should convert all the flag values to 1 if it zero and zero's to 1. How? Pls provide me the full coding for the stored procedure.
Thanx. 

View 2 Replies View Related

Trouble Updating SQLTable Using A Stored Procedure

Jan 30, 2004

If I run a update stored procedure on my SQLServer It work Fine.
But When I try it in my VB code, it's just do nothing not even an error message.

What I've got to do for being able to Update SQLTable with a stored procedure?

That's my VB code:


Dim objConnect As SqlConnection
Dim strConnect As String = System.Configuration.ConfigurationSettings.AppSettings("StringConn")

objConnect = New SqlConnection(strConnect)

Dim objCommand As New SqlCommand("internUpdate", objConnect)
objCommand.CommandType = CommandType.StoredProcedure

Try
Dim objParam As SqlParameter

objParam = objCommand.Parameters.Add("Id", SqlDbType.Int)
objParam.Direction = ParameterDirection.Input
objParam.Value = InternIDValue

objParam = objCommand.Parameters.Add("Address", SqlDbType.VarChar, 50)
objParam.Direction = ParameterDirection.Input
objParam.Value = Address.Value.Trim()

objParam = objCommand.Parameters.Add("City", SqlDbType.VarChar, 50)
objParam.Direction = ParameterDirection.Input
objParam.Value = City.Value.Trim()

objParam = objCommand.Parameters.Add("ProvinceCode", SqlDbType.Char, 2)
objParam.Direction = ParameterDirection.Input
objParam.Value = myProvince.SelectedValue

objParam = objCommand.Parameters.Add("PostalCode", SqlDbType.VarChar, 50)
objParam.Direction = ParameterDirection.Input
objParam.Value = PostalCode.Value.Trim()

objParam = objCommand.Parameters.Add("Phone", SqlDbType.VarChar, 50)
objParam.Direction = ParameterDirection.Input
objParam.Value = Phone1.Value.Trim()

objParam = objCommand.Parameters.Add("Phone2", SqlDbType.VarChar, 50)
objParam.Direction = ParameterDirection.Input
objParam.Value = Phone2.Value.Trim()

objParam = objCommand.Parameters.Add("Email", SqlDbType.VarChar, 50)
objParam.Direction = ParameterDirection.Input
objParam.Value = EmailAddress1.Value.Trim()

objParam = objCommand.Parameters.Add("Email2", SqlDbType.VarChar, 50)
objParam.Direction = ParameterDirection.Input
objParam.Value = EmailAddress2.Value.Trim()

objParam = objCommand.Parameters.Add("EmploymentStatusCode", SqlDbType.Char, 2)
objParam.Direction = ParameterDirection.Input
objParam.Value = myStatus.SelectedValue

objConnect.Open()
objCommand.ExecuteNonQuery()
objConnect.Close()

Catch ex As Exception
Exit Sub
End Try



Thanks!!

View 1 Replies View Related

Updating 2 Table At The Same Time Using Stored Procedure

Sep 14, 2004

G'day everyone...

I have two tables: Category and Product.
CategoryID is the Foreign Key of Product table.
I want to update those tables at the same time using stored procedure.

It will work like this.
If I update the Display column of Category table to have the value of 0, it will also update any records in the Product table -that has the same CategoryID- to have the value of 0 in its Display column.

I just read something about trigger and bit gives me idea that I might use it for this case, but don't know how to write the SQL.

Can anyone please help me...
Thanks...

View 2 Replies View Related

Access Crashes When Updating A Stored Procedure

Jul 20, 2005

Hello,I am having a problem when using access xp as a frontend for sql server2000.I have been trying to update a number of stored procedures (Just simpleadding fields etc) which results in access crashing with event ID 1000 and1001.Does anyone have any ideas as to what could be the problem?Thanks in advance..

View 3 Replies View Related

Stored Procedure Not Updating Database (no Errors Appearing)

Dec 1, 2003

Hi All,

I have a stored procedure (works form the SQL side). It is supposed to update a table, however it is not working, please help. What is supposed to happen is I have a delete statement deleting a payment from the payment table. When the delete button is pushed a trigger deletes the payment from the payment table and transfers it to the PaymentDeleted table. The stored procedure is supposed to update the PaymentDeleted table with the empID and reason for deleting, the delete and transfer work fine, however these 2 fields are not updated. Below is the sp and below that is the vb code. Thanks, Karen



ALTER PROCEDURE dbo.PaymentDeletedInfoTrail (@EmpID_WhoDeleted varchar(10), @Reason_Deleted varchar(255), @PmtDeletedID int)
AS
BEGIN

UPDATE dbo.PaymentDeleted
SET EmpID_WhoDeleted = @EmpID_WhoDeleted
WHERE PmtDeletedID = @PmtDeletedID

UPDATE dbo.PaymentDeleted
SET Reason_Deleted = @Reason_Deleted
WHERE PmtDeletedID = @PmtDeletedID

END



Private Sub cmdSubmit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdSubmit.Click
Me.Validate()
If Me.IsValid Then
Dim DR As SqlClient.SqlDataReader

Dim strPmtID As String
strPmtID = lblPmtIDDel.Text

Dim MySQL As String
MySQL = "DELETE From Payment WHERE PmtID = '" & strPmtID & "'"
Dim MyCmd As New SqlClient.SqlCommand(MySQL, SqlConnection1)
SqlConnection1.Open()
DR = MyCmd.ExecuteReader(System.Data.CommandBehavior.CloseConnection)
SqlConnection1.Close()


Dim strDeletePmt As String
strDeletePmt = lblPmtIDDel.Text

Dim cmd As New SqlClient.SqlCommand("PaymentDeletedInfoTrail", SqlConnection1)
cmd.CommandType = CommandType.StoredProcedure

Dim myParam As SqlClient.SqlParameter
myParam = cmd.Parameters.Add(New SqlClient.SqlParameter("@PmtDeletedID", SqlDbType.Int))
myParam.Direction = ParameterDirection.Input
myParam.Value = lblPmtIDDel.Text

myParam = cmd.Parameters.Add(New SqlClient.SqlParameter("@EmpID_WhoDeleted", SqlDbType.VarChar))
myParam.Value = txtEmpIDDelete.Text

myParam = cmd.Parameters.Add(New SqlClient.SqlParameter("@Reason_Deleted", SqlDbType.VarChar))
myParam.Value = txtDeleteComments.Text

SqlConnection1.Open()
cmd.ExecuteNonQuery()
SqlConnection1.Close()

End If
Response.Redirect("PaymentVerification.aspx")
End Sub

View 1 Replies View Related

Updating Specific Columns Through A Stored Procedure At Runtime

Feb 25, 2008

I have a question. I know its possible to create a dynamic query and do an exec @dynamicquery. Question: Is there a simpler way to update specific columns in a table at run time without doing if else for each column to determine which is null and which has a value because i'm running into a design dilemna on how to go about it.

FYI: All columns in the table design are set to null by default.

Thanks in advance,

Dimeji

View 4 Replies View Related

Help Send An Personal Email From Database Mail On Row Update-stored PROCEDURE Multi Update

May 27, 2008

hi need help how to send an email from database mail on row update
from stored PROCEDURE multi update
but i need to send a personal email evry employee get an email on row update
like send one after one email


i use FUNCTION i get on this forum to use split from multi update

how to loop for evry update send an single eamil to evry employee ID send one email

i update like this


Code Snippet
:

DECLARE @id nvarchar(1000)
set @id= '16703, 16704, 16757, 16924, 17041, 17077, 17084, 17103, 17129, 17134, 17186, 17190, 17203, 17205, 17289, 17294, 17295, 17296, 17309, 17316, 17317, 17322, 17325, 17337, 17338, 17339, 17348, 17349, 17350, 17357, 17360, 17361, 17362, 17366, 17367, 17370, 17372, 17373, 17374, 17377, 17380, 17382, 17383, 17385, 17386, 17391, 17392, 17393, 17394, 17395, 17396, 17397, 17398, 17400, 17401, 17402, 17407, 17408, 17409, 17410, 17411, 17412, 17413, 17414, 17415, 17417, 17418, 17419, 17420, 17422, 17423, 17424, 17425, 17426, 17427, 17428, 17430, 17431, 17432, 17442, 17443, 17444, 17447, 17448, 17449, 17450, 17451'
UPDATE s SET fld5 = 2
FROM Snha s
JOIN dbo.udf_SplitList(@id, ',') split
ON split.value = s.na
WHERE fld5 = 3

now
how to send an EMAIL for evry ROW update but "personal email" to the employee



Code Snippet
DECLARE @xml NVARCHAR(MAX)DECLARE @body NVARCHAR(MAX)
SET @xml =CAST(( SELECT
FirstName AS 'td','',
LastName AS 'td','' ,
SET @body = @body + @xml +'</table></body></html>'
EXEC msdb.dbo.sp_send_dbmail
@recipients =''
@copy_recipients='www@iec.com',
@body = @body,
@body_format ='HTML',
@subject ='test',
@profile_name ='bob'
END
ELSE
print 'no email today'


TNX

View 2 Replies View Related

Stored Procedure Definition Not Updating, Causing DTS Copy Error

Jun 27, 2007

I've got a weird one here. I'm running a DTS package on SQL Server2005. It copies a bunch of stored procedures. I renamed them on theoriginating server and ran the DTS again.The came over with the old name and code!I deleted the DTS and built it from scratch, and the same thinghappened.I ran SELECT * FROM sys.objects where type = 'P' on the source serverand the names were correctI'm explicitly checking which sp to copy rather than using Copy all. Ican see the sp namesI've deleted and recreated the sp on the source server using scriptsI've checked the source server nameI've Refreshed everywhereNothing worksWhy is up_Department_GetAllBySchool trying to be be pulled over whenit doesn't exist?Why is up_Department_GetBySchool not being pulled over when it doesexist?I've heard that SQL 2005 pre-SP2 has a problem where renaming anobject that has a text definition (like sprocs, functions, triggers,views) doesn't update the definition. So if you pull that objectdefinition and run it into your new database, it will use the originalscript, which has the original name.I ransp_helptext 'up_Department_GetBySchool'and checked the CREATE statement at the top. Sure enough, it had theold textI asked our NetAdmin to install SP2 on our server. Then I ransp_refreshsqlmodule 'up_Department_GetForSchool'and got this error:Invalid object name 'up_Department_GetAllForSchool'.So even the code which was supposed to fix it, doesn't. Has anyoneelse had this problem, and managed to fix it?--John Hunter

View 1 Replies View Related

Stored Procedure - Update Statement Does Not Seem To Update Straight Away

Jul 30, 2007

Hello,

I'm writing a fairly involved stored procedure. In this Stored Procedure, I have an update statement, followed by a select statement. The results of the select statement should be effected by the previous update statement, but its not. When the stored procedure is finish, the update statement seemed to have worked though, so it is working.

I suspect I need something, like a GO statement, but that doesnt seem to work for a stored procedure. Can anyone offer some assistance?

View 6 Replies View Related

Need Help With A SQL Update Stored Procedure

Jun 16, 2006

Can someone walk me through the code for my update_command event?Every article I read and every tutorial I walk through has a slightly different way of doing this task.It's confusing trying to understand which code-behind variables I need in my update_command event and how to pass them to a stored procedure.
Please help me connect the dots.
I have a SQL server table that looks like this (Both data types are char)
Status_Id            Status_DescriptionA                    ActiveP                    Planned
I have a SQL stored procedure that looks like this…
create procedure dbo.usp_Update_Status_Master(@status_id char(1),@status_description char(30))asupdate status_masterset status_description = @status_descriptionwhere status_id = @status_idGO
Here is my code behind…
Imports SystemImports System.DataImports System.Data.SqlClientImports System.ConfigurationImports System.Data.OdbcPublic Class WebForm1    Inherits System.Web.UI.Page    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load        If Not IsPostBack Then            Call LoadStatusMasterGrid()        End If    End Sub    Public Sub LoadStatusMasterGrid()        Dim connection As SqlConnection = New SqlConnection(ConfigurationSettings.AppSettings("sqlConn"))        connection.Open()        Try            Dim command As SqlCommand = _                New SqlCommand("usp_Select_Status_Master", connection)            Command.CommandType = CommandType.StoredProcedure            Dim adapter As SqlDataAdapter = New SqlDataAdapter(Command)            Dim table As DataTable = New DataTable            adapter.Fill(table)            dgStatusMaster.DataSource = table            dgStatusMaster.DataKeyField = "status_id"            dgStatusMaster.DataBind()        Catch ex As Exception            Console.WriteLine(ex.Message)            Throw        Finally            connection.Close()        End Try    End Sub    Private Sub dgStatusMaster_EditCommand(ByVal source As Object, _    ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles dgStatusMaster.EditCommand        dgStatusMaster.EditItemIndex = e.Item.ItemIndex        dgStatusMaster.DataBind()        Call LoadStatusMasterGrid()    End Sub    Private Sub dgStatusMaster_CancelCommand(ByVal source As Object, _    ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles dgStatusMaster.CancelCommand        dgStatusMaster.EditItemIndex = -1        Call LoadStatusMasterGrid()    End Sub    Private Sub dgStatusMaster_UpdateCommand(ByVal source As Object, _    ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles dgStatusMaster.UpdateCommand   ‘ How do I code this part?        End SubEnd Class
Thanks in advance for taking the time.Tim  

View 1 Replies View Related

Update To Stored Procedure

Feb 18, 2008

hi
i have 2 columns linked ( 1 to a textbox and the other to drop down list)
when i try to update i get 1 of the to the update SP but not the other and get this error
Procedure or Function 'Update_ActiveCity' expects parameter '@Cities', which was not supplied.
 
 
_________________ this is the code of the aspx ____________
 
<asp:GridView ID="grdD" runat="server" AutoGenerateColumns="False" DataKeyNames="CountryCode" DataSourceID="dsGrdD" OnRowDataBound="grdD_RowDataBound"><Columns><asp:TemplateField><ItemTemplate>
<asp:TextBox ID="txtCountry" runat="server" Text='<%# Bind("Country") %>' />
<asp:DropDownList ID="ddlCities" runat="server" />
</ItemTemplate></asp:TemplateField></Columns></asp:GridView>
 
<asp:SqlDataSource ID="dsGrdD" runat="server" ConnectionString="<%$ ConnectionStrings:DBConnectionString %>"
SelectCommand="Select_Cities" SelectCommandType="StoredProcedure" UpdateCommand="'Update_ActiveCity' " UpdateCommandType="StoredProcedure" CacheExpirationPolicy="Sliding">
<SelectParameters> <asp:SessionParameter Name="ListCode" SessionField="ListCode" Type="String" /> </SelectParameters>
</asp:SqlDataSource>
_______________________ this is the code behind ____________________protected void grdD_RowDataBound(object sender, GridViewRowEventArgs e)
{DropDownList ddl = e.Row.FindControl("ddlCities") as DropDownList;if (ddl != null)
{
string s = DataBinder.Eval(((GridViewRow)e.Row).DataItem, "Cities").ToString();ddl.DataSource = s.Split(',');
ddl.DataBind();
}
}
_______________________________________________________________________________-

View 9 Replies View Related

Update Stored Procedure

May 3, 2008

here is the procedureALTER PROCEDURE dbo.UpdateContact
(@ContactId bigint,@FirstName nvarchar(50),
@LastName nvarchar(50),@Telephone nvarchar(50),
@Addressline nvarchar(150),@State nvarchar(100),
@City nvarchar(100),@PostalCode varchar(50),
@Email nvarchar(50),
@MobilePhone varchar(50))
AS
SET NOCOUNT ON
 UPDATE ContactSET FirstName = @FirstName,
LastName = @LastName,
Telephone = @Telephone,
MobilePhone = @MobilePhone,
Email = @Email,
Addressline = @Addressline,
City = @City,
State = @State,
PostalCode = @PostalCodeWHERE ContactId = @ContactId
 
RETURN
what is the problem if i execute the storedprocedure separately it is working but when i call the storedprocedure in the code it fails.
It gives an error as "syntax error near Updatecontact"
Any ideas???
 

View 1 Replies View Related

Stored Procedure Update..

May 27, 2004

I'm sorry for asking a lot of questions, but it is driving me crazy that I can't figure out how to do this update..

Let say I got two tables, both with an "ID".

TBL 1 TBL 2
ID <--> ID
STATUS


If they match, I want to update the status on tbl1 as "matched"

How would I preform this with a stored procedure??

I am currently using a view and then updating the view (I KNOW ITS BAD!)

View 4 Replies View Related

Update Stored Procedure HELP

Apr 22, 2005

I have an Update stored procedure that I am trying to update in the query analyzer to make sure it works, because it is not working from .NET.
Here is the stored procedure:
CREATE PROCEDURE Update_Homeowner (@TransactionID int, @DealerID varchar (50), @FirstName varchar(50), @LastName varchar(50), @Add1 varchar(50), @Add2 varchar(50), @City varchar(50), @State varchar(50), @Zip varchar(50)) 
AS UPDATE Homeowner
SET  @DealerID=DealerID, @FirstName=FirstName,@LastName=LastName,@Add1=Add1,@Add2=Add2,@City=City,@State=State,@Zip=Zip
WHERE  TransactionID = @TransactionID
GO
Here is how I am calling it in the Query Analyzer:
Update_Homeowner 47,'VT125313','test','tests','barb','','test','mo','23423'
It will not update, but I get the message (1 row(s) affected).
Any ideas???Thanks,Barb Cox

View 4 Replies View Related

IF / ELSE -- Update Stored Procedure

Aug 4, 2005

What am I doing wrong in this code:<CODE>Select Results.custIDFrom Results If (Results.custID = DRCMGO.custID)Begin Update Results SET Results.DRCMGO = 'Y'ENDELSEBegin Update Results SET Results.DRCMGO = 'N'END<CODE>I'm trying to do an IF / ELSE statement:-- if the custIDs in my Results table and my DRCMGO table match then I want to set DRCMGO to Y-- if they don't match I want to set it to NWhat is wrong with this syntax.  If someone could let me know i would greatly appriciate it (I'm doing it as SQL Books Online is telling me to)  Thanks in advance everyone.  RB

View 1 Replies View Related

Update Stored Procedure Help!!!

Nov 30, 2005

Trying to Get this to work correctly...I Only want the latest(meaning most recent) entry of the Name(Column) Database = ProductsTest2To be also entered into Name(Column) Database = LocationOutsideUSABut When I run the code below it updates all fields that are contained in the entire [Name(Column)] of Database = LocationOutsideUSA  with the same data entered.Thanks Inadvance...____________________________________________________________________________________UPDATE LocationOutsideUSASET   Name = ProductsTest2.NameFROM
ProductsTest2SELECT MAX(Name) AS MaxName FROM ProductsTest2WHERE  ProductsTest2.UID = ProductsTest2.UID

View 3 Replies View Related

Update From Stored Procedure

May 16, 2002

Is it possible to update a temporary file inside a stored procedure from calling another procedure. I am trying to leverage a sp that does a custom pricing routine and want to call it from another sp like so, the second procedure returns a set of records, very simular to a select.

UPDATE #tb_items
SET price = T1.sellprice, freight = T1.freight
FROM (usp_pricecalculator '700', '', '', '', '("B354-20")' ,'1') T1
WHERE #tb_items.itnbr = T1.itnbr

I have also looked into calling this sp into a cursor and updating in a loop on the cursor and had no luck

please help, much appreciation

JIM

View 1 Replies View Related

Update Stored Procedure

Jan 7, 2005

I'm updating a record using the following SP:

CREATE PROCEDURE dbo.Sp_Del_Req_Record
(
@abrID int,
@logl_del_dt datetime,
@phys_del_dt datetime
)
AS
UPDATE DIM_ABR_REQ_DETLS
SET ABR_DETLS_LOGL_DEL_DT = @logl_del_dt,
ABR_DETLS_PHYS_DEL_DT = @phys_del_dt
WHERE ABR_DETLS_ID = @abrID
GO

I have the following command code:
Dim Sp_Del_Req_Record__abrID
Sp_Del_Req_Record__abrID = ""
if(Request("AlloFundID") <> "") then Sp_Del_Req_Record__abrID = Request("AlloFundID")

Dim Sp_Del_Req_Record__logl_del_dt
Sp_Del_Req_Record__logl_del_dt = ""
if(Now() <> "") then Sp_Del_Req_Record__logl_del_dt = Now()

Dim Sp_Del_Req_Record__phys_del_dt
Sp_Del_Req_Record__phys_del_dt = ""
if(Now() <> "") then Sp_Del_Req_Record__phys_del_dt = Now()

%>
<%

set Sp_Del_Req_Record = Server.CreateObject("ADODB.Command")
Sp_Del_Req_Record.ActiveConnection = MM_DBConn_STRING
Sp_Del_Req_Record.CommandText = "dbo.Sp_Del_Req_Record"
Sp_Del_Req_Record.CommandType = 4
Sp_Del_Req_Record.CommandTimeout = 0
Sp_Del_Req_Record.Prepared = true
Sp_Del_Req_Record.Parameters.Append Sp_Del_Req_Record.CreateParameter("@RETURN_VALUE", 3, 4)
Sp_Del_Req_Record.Parameters.Append Sp_Del_Req_Record.CreateParameter("@abrID", 3, 1,4,Sp_Del_Req_Record__abrID)
Sp_Del_Req_Record.Parameters.Append Sp_Del_Req_Record.CreateParameter("@logl_del_dt", 135, 1,8,Sp_Del_Req_Record__logl_del_dt)
Sp_Del_Req_Record.Parameters.Append Sp_Del_Req_Record.CreateParameter("@phys_del_dt", 135, 1,8,Sp_Del_Req_Record__phys_del_dt)
Sp_Del_Req_Record.Execute()

%>

I get a wrong data type error thrown at the following line:
Sp_Del_Req_Record.Parameters.Append Sp_Del_Req_Record.CreateParameter("@abrID", 3, 1,4,Sp_Del_Req_Record__abrID)

I'm not sure where I am going wrong.
Any help is appreciated. Thanks.
-D-

View 3 Replies View Related

Update Stored Procedure

Jan 22, 2006

I need to create a stored procedure that will update, an insert will try to insert an entire row and I am only trying to update old data with new data. For instance if I move all the 99 terms from the active table to the term table and lets say for example their [hiredate], [ID], [firstname], but after the update is done I realize I forgot to include the [lastname] field, see what I mean??? Or I just wanted to UPDATE old data with new data?? Would this stored procedure work


CREATE PROCEDURE [InsertTerms]
AS
INSERT INTO [GamingCommissiondb].[dbo].[TERMINATION]
(ReasonTerminated)

SELECT a.DESCRIPTION
FROM DesireeTerm3
WHERE TERIMINATION.TM#= DesireeTerm3.Employee
RETURN
GO

View 14 Replies View Related

UPDATE Stored Procedure

May 9, 2007

In this stored procedure I attempt to update the AGE and SERV_AGE fields with the days difference between a date parameter and a List Date and Service Date in any of a number of tables we have that contain these two fields. I attempt to pass in the date parameter and the table name to use.
=====================================
CREATE PROCEDURE up_UpdateAcctAge
@strTableName nvarchar(50),
@dteWeekDate datetime

AS
UPDATE @strTableName
SET AGE = DATEDIFF(D, ASSIGN_DT, CONVERT(DATETIME, @dteWeekDate, 102)),
SERV_AGE = DATEDIFF(D, SERV_DT, CONVERT(DATETIME,@dteWeekDate, 102))
GO
=========================================

Any idea why I am getting the following message when I check syntax?

Server: Msg 137, Level 15, State 2, Procedure up_UpdateAcctAge, Line 7
Must declare the variable '@strTableName'.

Any help you can give this novice is appreciated.

View 4 Replies View Related

Update Stored Procedure Help

Jan 2, 2008

I have been given the task to create a stored procedure that will update employee's leave balances. My part of the task was just to create the stored procedure within my sql server 2005 database that the programmer can use each time leave balances change in the current leave system. There are 4 types of leave balances: Annual Leave, Sick Leave, Family Leave, and Other Leave. The problem I am having is that I was told that all 4 values will not be passed each time, so my stored procedure needs to allow empty/Null values to be entered for some fields without overwriting the existing data. Also any errors should not cause issues with the current leave system, I am guessing if an error occurs then I need an email sent to me stating the issue and if successful then no message.

I have written this stored procedure:


CREATE PROCEDURE [dbo].[usp_updateuser]

@Emp_SSN int,

@Annual_Forward decimal(10,2),

@Sick_Forward decimal(10,2),

@Family_Forward decimal(10,2),

@Other_Forward decimal(10,2)

AS

UPDATE OT_MAIN

SET

EmpAnnual_Forward = @Annual_Forward,

EmpSick_Forward = @Sick_Forward,

EmpFamily_Forward = @Family_Forward,

EmpOther_Forward = @Other_Forward

WHERE

Emp_SSN=@Emp_SSN


I can execute the procedure using exec and then passing the 4 variables, but I don't know how to do the errors and messages and the allow null values without over writing.

Any help would be greatly appreciated. I am really new to sql server, and expecially new to stored procedures.

Thank you.

View 3 Replies View Related

Stored Procedure Update Problem

Dec 7, 2006

HI
 
I WRITTEN STORED PROCEDUE UPDATE.
isuppose in my table there are 2 rows belongs to same tr id.
trid     city
1     aaaa
1    bbb
 
 
i want result like
 
trid    city
1      ttttt
1    jjjjj
 
but i m getting result like
 
 
trid  city
1   jjjj
1  jjjj
i wnat to update city individually.
like i will change 1 st row city as 'ttttt'
and 2 nd row city as 'jjjjjj'
for paticular tr id.
 
i ma getting problem like its updating city for  2 rows for that particular tr id .
i wnat to update city individually.
please help me.
 
thanks
swapprose.
 

View 1 Replies View Related

Insert Or Update With Stored Procedure

Dec 27, 2006

I'm doing this more as a learning exercise than anything else.  I want to write a stored procedure that I will pass a key to it and it will look in the database to see if a row exists for that key.  If it does, then it needs to update the row on the DB, if not, then it needs to insert a new row using the key as an indexed key field on the database.for starters can this even be done with a stored procedure?if so, can someone provide some guidance as to how?thanks in advance,Burr

View 5 Replies View Related

Stored Procedure To Update Ntext Value In SQL

Jul 4, 2007

Hi
My SP to update a value type ntext don't work,  ALTER PROCEDURE UpdateMultiContentFullDescriptionByID
(@ContentID int,
@FullDescription ntext)
AS
UPDATE MultifunctionalContent
SET FullDescription = @FullDescription
WHERE ContentID = @ContentID
RETURNPublic Sub UpdateMultiContentFullDescriptionByID(ByVal ContentID As String, ByVal FullDescription As String)
' Create Instance of Connection and Command Object
Dim myConnection As SqlConnection = New SqlConnection(Const.ConnectionString)
Dim myCommand As SqlCommand = New SqlCommand("UpdateMultiContentFullDescriptionByID", myConnection)
' Mark the Command as a SPROC
myCommand.CommandType = CommandType.StoredProcedure

' Add an input parameter and supply a value for it
myCommand.Parameters.Add("@ContentID", SqlDbType.Int, 4)
myCommand.Parameters("@ContentID").Value = ContentID

' Add an input parameter and supply a value for it
myCommand.Parameters.Add("@FullDescription", SqlDbType.NText, 8000)
myCommand.Parameters("@FullDescription").Value = FullDescription

' Open the connection and execute the Command
myConnection.Open()
myCommand.ExecuteNonQuery()
myConnection.Close()
End Sub Then how to ...

View 2 Replies View Related

Stored Procedure - Update (Succesful?)

Dec 11, 2007

I wrote a stored procedure to update a record.  It works just fine.But in my VB.Code how do I prompt myself if the Update was unsuccessful?i.e. In my SQL statement of my Store Procedure, if I pass an Invalid parameter PassOCN, I want my user to know the update was not successful.  The parameter string does not exist in my table to update. VB code: Protected Sub Button13_Click(ByVal sender As Object, ByVal e As System.EventArgs) ' Update OCN designation in tblPortCarriersList ' Define database connection
Dim connect As String = "Server=localhostSqlExpress;" & _ "Database=lnp;Integrated Security=True" Using conn As New SqlConnection(connect) 'Open the connection
conn.Open()

' Using Store Procedure
Dim passOCN As String Dim updateOCN As String
passOCN = "1236"
updateOCN = "2287"

Dim Update As New SqlCommand() Update.Connection = conn Update.CommandType = Data.CommandType.StoredProcedure Update.CommandText = "sp_UpdateOcnTblPortCarriers"
Update.Parameters.Add("@UpdateOCN", System.Data.SqlDbType.NVarChar, 4) Update.Parameters.Add("@PassOCN", System.Data.SqlDbType.NVarChar, 4) Update.Parameters("@UpdateOCN").Value = updateOCN Update.Parameters("@PassOCN").Value = passOCN Update.ExecuteNonQuery() End Using usersLabel.Text = "Finished Updating OCN tblPortCarrier"

End Sub Stored Procedure: USE [lnp]GOSET ANSI_NULLS ONGOSET QUOTED_IDENTIFIER ONGOALTER PROCEDURE [dbo].[sp_UpdateOcnTblPortCarriers] -- Add the parameters for the stored procedure here@UpdateOCN NVarChar(4),@PassOCN NVarChar(4)ASBEGIN-- SET NOCOUNT ON added to prevent extra result sets from-- interfering with SELECT statements.SET NOCOUNT ON; -- Update statements for procedure hereUPDATE [dbo].tblPortCarriers SET [CarrierPortOCN] = @UpdateOCN Where [CarrierPortOCN] = @PassOCNENDThanks in advance for your assistance. 

View 8 Replies View Related

Stored Procedure Update Problem

Apr 30, 2008

Hey guys.I have a problem with the an update stored procedure.It seems the code is executing and there are no errors, but there record in the database that should be updating isn't having any information changed. My vb.net code is thus:  'Create a New Connection for the Stored Procedure
Dim myConnection As New Data.SqlClient.SqlConnection(Me.SqlDataSource1.ConnectionString)
myConnection.Open()
Dim myCommand As New Data.SqlClient.SqlCommand("UPDATE_FORM", myConnection)
myCommand.CommandType = Data.CommandType.StoredProcedure
Dim case_link_id = CType(Me.FormView1.FindControl("label1"), Label).Text
Dim case_link_id_number = CInt(case_link_id)
'Add the rest of the insert parameters

myCommand.Parameters.AddWithValue("Form_Case_Link_ID", case_link_id_number)

If ((CType(Me.FormView1.FindControl("Returned_DateTextBox"), TextBox).Text <> "")) Then
myCommand.Parameters.AddWithValue("Returned_Date", Convert.ToDateTime(CType(Me.FormView1.FindControl("Returned_DateTextBox"), TextBox).Text))

Else : myCommand.Parameters.AddWithValue("Returned_Date", DBNull.Value)

End If

myCommand.Parameters.AddWithValue("Na", CType(Me.FormView1.FindControl("NA"), CheckBox).Checked)

myCommand.Parameters.AddWithValue("Notes", CType(Me.FormView1.FindControl("NotesTextBox"), TextBox).Text)

'Execute the command
myCommand.ExecuteNonQuery()

myConnection.Close()

Response.Redirect("~/success.aspx")   and my stored procedure looks like this:  ALTER PROCEDURE [dbo].[UPDATE_FORM]
@form_case_link_id as int,
@Returned_Date as datetime,
@NA as bit,
@Notes as varchar(500)

as UPDATE tbl_Forms_Case_Link

SET

returned_date = @returned_date,
na = @na,
notes = @notes

WHERE form_case_link_id = @form_case_link_id  Can anyone help me with this? Many thanks.DS

View 4 Replies View Related

Stored Procedure Update Problem

Dec 3, 2003

I have a webpage (language is c#) that is being used to add, update and delete information stored in a database. The database uses a date field and a location field as the primary key value so that only one entry can be made for each day for any particular location. The problem I am having is that when the user clicks submit the information should either be updated or added for the particular day and location. It works fine when I am adding a new entry but if an entry already exists it will not update the information. The delete button also works properly. I am passing parameter values from asp:textboxes to a stored procedure when the user clicks on the submit button. In the procedure I am determining whether or not there is already information for that location and date, if there is the information should be updated, if not the information should be inserted. Here is the sample code that I am using right now, if anyone could please explain why the insert statement works fine but the update won't I would greatly appreciate it.

Stored Procedure

CREATE PROCEDURE uSP_AddSRT

@SRTdate DateTime = null,
@Location VarChar(30) =null,
@TruckNonWarWorked Float = null,
@TruckNonWarBilled Float = null,
@TruckWarWorked Float = null,
@TruckWarBilled Float = null,
@ServiceNonWarWorked Float = null,
@ServiceNonWarBilled Float = null,
@ServiceWarWorked Float = null,
@ServiceWarBilled Float = null,
@FtlWorked Float = null,
@FtlBilled Float = null,
@DetroitWorked Float = null,
@DetroitBilled Float = null,
@CatWorked Float = null,
@CatBilled Float = null,
@CumminsWorked Float = null,
@CumminsBilled Float = null,
@EatonWorked Float = null,
@EatonBilled Float = null,
@MeritorWorked Float = null,
@MeritorBilled Float = null,
@MercWorked Float = null,
@MercBilled Float = null,
@FccWorked Float = null,
@FccBilled Float = null,
@DriveLineWorked Float = null,
@DriveLineBilled Float = null,
@Comments Text = null
AS
If EXISTS(SELECT * FROM dbo.tblSRT WHERE dbo.tblSRT.Location = @Location AND dbo.tblSRT.SRTdate = @SRTdate)

begin
UPDATE dbo.tblSRT
SET
TruckNonWarWorked = @TruckNonWarWorked,
TruckNonWarBilled = @TruckNonWarBilled,
TruckWarWorked = @TruckWarWorked,
TruckWarBilled = @TruckWarBilled,
ServiceNonWarWorked = ServiceNonWarWorked,
ServiceNonWarBilled = @ServiceNonWarBilled,
ServiceWarWorked = @ServiceWarWorked,
ServiceWarBilled = @ServiceWarBilled,
FtlWorked = @FtlWorked,
FtlBilled = @FtlBilled,
DetroitWorked = @DetroitWorked,
DetroitBilled = @DetroitBilled,
CatWorked = @CatWorked,
CatBilled = @CatBilled,
CumminsWorked =@CumminsWorked,
CumminsBilled = @CumminsBilled,
EatonWorked = @EatonWorked,
EatonBilled = @EatonBilled,
MeritorWorked = @MeritorWorked,
MeritorBilled = @MeritorBilled,
MercWorked = @MercWorked,
MercBilled = @MercBilled,
FccWorked = @FccWorked,
FccBilled = @FccBilled,
DriveLineWorked = @DriveLineWorked,
DriveLineBilled = @DriveLineBilled,
Comments = @Comments

WHERE Location = @Location AND SRTdate = @SRTdate

End

Else

begin

INSERT INTO dbo.tblSRT(SRTdate,Location,TruckNonWarWorked,TruckNonWarBilled,TruckWarWorked,TruckWarBilled,ServiceNonWarWorked,ServiceNonWarBilled,
ServiceWarWorked,ServiceWarBilled,FtlWorked,FtlBilled,DetroitWorked,DetroitBilled,CatWorked,CatBilled,CumminsWorked,
CumminsBilled,EatonWorked,EatonBilled,MeritorWorked,MeritorBilled,MercWorked,MercBilled,FccWorked,FccBilled,DriveLineWorked,DriveLineBilled,Comments)
VALUES(@SRTdate,@Location,@TruckNonWarWorked,@TruckNonWarBilled,@TruckWarWorked,
@TruckWarBilled,@ServiceNonWarWorked,@ServiceNonWarBilled,@ServiceWarWorked,@ServiceWarBilled,@FtlWorked,@FtlBilled,@DetroitWorked,
@DetroitBilled,@CatWorked,@CatBilled,@CumminsWorked,@CumminsBilled,@EatonWorked,@EatonBilled,@MeritorWorked,@MeritorBilled,@MercWorked,@MercBilled,@FccWorked,@FccBilled,@DriveLineWorked,@DriveLineBilled,@Comments)

End
GO



AddSRT.aspx

//now create the connection, the sql statement, and the sql parameters
SqlConnection connection = new SqlConnection("server=localhost; uid=sa; pwd=; Database=SRTworkTime");
SqlCommand command = new SqlCommand ("uSP_AddSRT", connection);
command.CommandType = CommandType.StoredProcedure;

command.Parameters.Add("@SRTdate",SqlDbType.DateTime);
command.Parameters[0].Value = Date.Value;

command.Parameters.Add("@Location",SqlDbType.VarChar,30);
command.Parameters[1].Value = Location.Value;

command.Parameters.Add("@TruckNonWarWorked",SqlDbType.Float);
if(txtTruckNonWarWorked.Text != "" && txtTruckNonWarWorked.Text != null){
command.Parameters[2].Value = txtTruckNonWarWorked.Text;
}
else{
command.Parameters[2].Value = null;
}

command.Parameters.Add("@TruckNonWarBilled",SqlDbType.Float);
if(txtTruckNonWarBilled.Text != "" && txtTruckNonWarBilled.Text != null){
command.Parameters[3].Value = txtTruckNonWarBilled.Text;
}
else{
command.Parameters[3].Value = null;
}

command.Parameters.Add("@TruckWarWorked",SqlDbType.Float);
if(txtTruckWarWorked.Text != "" && txtTruckWarWorked.Text != null){
command.Parameters[4].Value = txtTruckWarWorked.Text;
}
else{
command.Parameters[4].Value = null;
}

command.Parameters.Add("@TruckWarBilled",SqlDbType.Float);
if(txtTruckWarBilled.Text != "" && txtTruckWarBilled.Text != null){
command.Parameters[5].Value = txtTruckWarBilled.Text;
}
else{
command.Parameters[5].Value = null;
}

command.Parameters.Add("@ServiceNonWarWorked",SqlDbType.Float);
if(txtServiceNonWarWorked.Text != "" && txtServiceNonWarWorked.Text != null){
command.Parameters[6].Value = txtServiceNonWarWorked.Text;
}
else{
command.Parameters[6].Value = null;
}

command.Parameters.Add("@ServiceNonWarBilled",SqlDbType.Float);
if(txtServiceNonWarBilled.Text != "" && txtServiceNonWarBilled.Text != null){
command.Parameters[7].Value = txtServiceNonWarBilled.Text;
}
else{
command.Parameters[7].Value = null;
}

command.Parameters.Add("@ServiceWarWorked",SqlDbType.Float);
if(txtServiceWarWorked.Text != "" && txtServiceWarWorked.Text != null){
command.Parameters[8].Value = txtServiceWarWorked.Text;
}
else{
command.Parameters[8].Value = null;
}

command.Parameters.Add("@ServiceWarBilled",SqlDbType.Float);
if(txtServiceWarBilled.Text != "" && txtServiceWarBilled.Text != null){
command.Parameters[9].Value = txtServiceWarBilled.Text;
}
else{
command.Parameters[9].Value = null;
}

command.Parameters.Add("@FtlWorked",SqlDbType.Float);
if(txtFtlWorked.Text != "" && txtFtlWorked.Text != null){
command.Parameters[10].Value = txtFtlWorked.Text;
}
else{
command.Parameters[10].Value = null;
}

command.Parameters.Add("@FtlBilled",SqlDbType.Float);
if(txtFtlBilled.Text != "" && txtFtlBilled.Text != null){
command.Parameters[11].Value = txtFtlBilled.Text;
}
else{
command.Parameters[11].Value = null;
}

command.Parameters.Add("@DetroitWorked",SqlDbType.Float);
if(txtDetroitWorked.Text != "" && txtDetroitWorked.Text != null){
command.Parameters[12].Value = txtDetroitWorked.Text;
}
else{
command.Parameters[12].Value = null;
}
command.Parameters.Add("@DetroitBilled",SqlDbType.Float);
if(txtDetroitBilled.Text != "" && txtDetroitBilled.Text != null){
command.Parameters[13].Value = txtDetroitBilled.Text;
}
else{
command.Parameters[13].Value = null;
}

command.Parameters.Add("@CatWorked",SqlDbType.Float);
if(txtCatWorked.Text != "" && txtCatWorked.Text != null){
command.Parameters[14].Value = txtCatWorked.Text;
}
else{
command.Parameters[14].Value = null;
}

command.Parameters.Add("@CatBilled",SqlDbType.Float);
if(txtCatBilled.Text != "" && txtCatBilled.Text != null){
command.Parameters[15].Value = txtCatBilled.Text;
}
else{
command.Parameters[15].Value = null;
}

command.Parameters.Add("@CumminsWorked",SqlDbType.Float);
if(txtCumminsWorked.Text != "" && txtCumminsWorked.Text != null){
command.Parameters[16].Value = txtCumminsWorked.Text;
}
else{
command.Parameters[16].Value = null;
}

command.Parameters.Add("@CumminsBilled",SqlDbType.Float);
if(txtCumminsBilled.Text != "" && txtCumminsBilled.Text != null){
command.Parameters[17].Value = txtCumminsBilled.Text;
}
else{
command.Parameters[17].Value = null;
}

command.Parameters.Add("@EatonWorked",SqlDbType.Float);
if(txtEatonWorked.Text != "" && txtEatonWorked.Text != null){
command.Parameters[18].Value = txtEatonWorked.Text;
}
else{
command.Parameters[18].Value = null;
}

command.Parameters.Add("@EatonBilled",SqlDbType.Float);
if(txtEatonBilled.Text != "" && txtEatonBilled.Text != null){
command.Parameters[19].Value = txtEatonBilled.Text;
}
else{
command.Parameters[19].Value = null;
}

command.Parameters.Add("@MeritorWorked",SqlDbType.Float);
if(txtMeritorWorked.Text != "" && txtMeritorWorked.Text != null){
command.Parameters[20].Value = txtMeritorWorked.Text;
}
else{
command.Parameters[20].Value = null;
}

command.Parameters.Add("@MeritorBilled",SqlDbType.Float);
if(txtMeritorBilled.Text != "" && txtMeritorBilled.Text != null){
command.Parameters[21].Value = txtMeritorBilled.Text;
}
else{
command.Parameters[21].Value = null;
}

command.Parameters.Add("@MercWorked",SqlDbType.Float);
if(txtMercWorked.Text != "" && txtMercWorked.Text != null){
command.Parameters[22].Value = txtMercWorked.Text;
}
else{
command.Parameters[22].Value = null;
}

command.Parameters.Add("@MercBilled",SqlDbType.Float);
if(txtMercBilled.Text != "" && txtMercBilled.Text != null){
command.Parameters[23].Value = txtMercBilled.Text;
}
else{
command.Parameters[23].Value = null;
}

command.Parameters.Add("@FccWorked",SqlDbType.Float);
if(txtFccWorked.Text != "" && txtFccWorked.Text != null){
command.Parameters[24].Value = txtFccWorked.Text;
}
else{
command.Parameters[24].Value = null;
}

command.Parameters.Add("@FccBilled",SqlDbType.Float);
if(txtFccBilled.Text != "" && txtFccBilled.Text != null){
command.Parameters[25].Value = txtFccBilled.Text;
}
else{
command.Parameters[25].Value = null;
}

command.Parameters.Add("@DriveLineWorked",SqlDbType.Float);
if(txtDriveLineWorked.Text != "" && txtDriveLineWorked.Text != null){
command.Parameters[26].Value = txtDriveLineWorked.Text;
}
else{
command.Parameters[26].Value = null;
}

command.Parameters.Add("@DriveLineBilled",SqlDbType.Float);
if(txtDriveLineBilled.Text != "" && txtDriveLineBilled.Text != null){
command.Parameters[27].Value = txtDriveLineBilled.Text;
}
else{
command.Parameters[27].Value = null;
}

command.Parameters.Add("@Comments",SqlDbType.Text);
if(txtComments.Text != "" && txtComments.Text != null){
command.Parameters[28].Value = txtComments.Text;
}
else{
command.Parameters[28].Value = null;
}

//open the connection and execute the query
connection.Open();
command.ExecuteNonQuery();
connection.Close();

Response.Redirect("AddSRTConfirm.aspx");
Thanks,
Brian Nicoloff

View 3 Replies View Related

Stored Procedure Update Table

Jan 20, 2004

Hi,

I've got a stored procedure which should update a table (add new customer record)
When I run it locally everythings fine,

Since uploading it all to the web it no longer seems to add a new record,
I've debugged it and it seems that the output parameters is set to nothing.

I believe it's a permissions issue but the user i'm using has full access to both the table
and permission to execute the stored procedure is there any error handling I can
do to capture the exact error? the code I use to execute the sProc is below

thanks for any help

Dave



Try
myConnection.Open()
myCommand.ExecuteNonQuery()
myConnection.Close()

' Calculate the New CustNo using Output Param from SPROC
Dim custNo As Integer = CInt(parameterCustNo.Value)

Return custNo.ToString()
Catch
<---This is where it's dropping in can I put any
Error handling in to show me the error?
Return String.Empty
End Try

View 3 Replies View Related







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