Showing posts with label update. Show all posts
Showing posts with label update. Show all posts

Tuesday, March 27, 2012

Create a trigger to update a row that's been inserted or updated

Hi

Apologies if this is a silly question

I have a basic table "Customer" which has

Id

Address1

Address2

Address3

Town

County

Postcode

SearchData

After I insert or Update a row in this table I need to update the SearchData column

with

UPPER(ADDRESS1) + UPPER(ADDRESS2) + UPPER(TOWN) + UPPER(POSTCODE)

only for that Id

I'm sure this is only a basic update but all the examples I can find are for inserting into other tables not the row itself.

Regards

David

Instead of using the trigger better you can go with Computed Columns...

here it is,

Code Snippet

Createtable Customer

(

IdintNOTNULL,

Address1varchar(100)NOTNULL,

Address2varchar(100)NOTNULL,

Address3varchar(100)NULL,

Townvarchar(100)NOTNULL,

Countyvarchar(100)NULL,

Postcodevarchar(100)NOTNULL,

SearchDataasUPPER(ADDRESS1)+UPPER(ADDRESS2)+UPPER(TOWN)+UPPER(POSTCODE)PERSISTED --Persisted only used on SQL Server 2005

)

|||I would not recommend using the 'PERSISTED' keyword unless you are attempting to solve a particular problem.|||

Hi

That was really helpful.

Thanks

David

Thursday, March 22, 2012

Create a custom webpage to edit/update a table in a SQL database.

Hi everyone, this is is my first post, so please replyStick out tongue and help.

I'm working on a project right now that uses asp 2.0 and SQL server 2005 express edition. This is a general idea of the project. In our company some of us receive ECO notifications (engineering change orders) for our products and we need to implement these to the test scripts that are on the production floor. So the project is about entering the new ECO into a database which will send an automatic notification to our test team. When they receive the notification they will have to sign in to the website and introduce their login and password to sign off the ECO (Following some checkpoints already defined by me, for example, Area ready, Test script modification necessary, new firmware introduction, comments, etc...) but I also need to record WHO and WHEN sign that ECO. We have 3 different test areas in our factory: Electrical, Functional and Systems, so all THREE areas must be signed off in order to the ECO go to a IMPLEMENTED state (at this point i need to send a new email saying that the eco has been implemented in all three areas).

So far I've completed the following things:

-users validation (logins, areas)

-New custom entry form for the ECOs and automatic email notification (part of what I did is described below).

Dim ECODataSourceAsNew SqlDataSource()ECODataSource.ConnectionString = ConfigurationManager.ConnectionStrings("ECO_ICSConnectionString1").ToString()

ECODataSource.InsertCommandType = SqlDataSourceCommandType.StoredProcedure

ECODataSource.InsertCommand ="EcoNew"

ECODataSource.InsertParameters.Add("EcoNumber", EcoNumberTextBox.Text)

ECODataSource.InsertParameters.Add("EcoDescription", EcoDescriptionTextBox.Text)

ECODataSource.InsertParameters.Add("EcoMandatory", EcoMandatoryDropDownList.Text)

-Depending on which test area is the the engineering from, I can filter the ECOs and just shows the ones that their test area is pending. (using GridView)

But I'm stuck right now when the engineers have to sign the ECO for their test areas. I was able to use the Gridview and DetailsView to EDIT most of the things that I need. But there are somethings that I don't like:

1. When using the EDIT option on Gridview or Detailsview, all fields can be edited including ECO number, description and mandatory, which I don't want them to change. If I set those columns to read only, when editing that row again. It gives me an error that says that the ECOnumber can't be NULL, but if I remove these 3 columns the Engineer will not know which ECO they have sign. They are only going to be able to see the EcoId, which doesn't say much.

2. Also I saw that I wasn't able to do is to enter the USER login and CURRENT system date and time automatically. I don't want them to manually enter the date and their login manually.

3. Finally, when the last area signs the ECO, I want to update that record and set a flag that tells me that the ECO has been completed.

So what I really want is to create some sort of form (textboxes, labels, checkboxes, etc.) that will UPDATE the selected ECO from the gridview for instance. So when I select the row from the GridView, It will show the data (Econumber, description and mandatory as READ ONLY) and use the rest of the things as INPUT for the engineer to complete. At the end an "update button" and when I click it, It will enter/update the data on that specific row, but including the time and user login as well.

Also to check if the other 2 areas have signed and if so, change the ECOReadiness flag to 1 and send the email.

Is there a code like the one I used above to do this ? Or if you think there a better way to do this, I'll be very glad to hear it.

I'm new using sql and asp, so If i'm asking some dumb questions please forgive me.Smile.

Here's my table definition for your reference:

EcoId - primary key.

EcoNumber

EcoDescription

EcoMandatory

EcoReadiness <- Flag for the entire ECO, when ALL 3 areas have signed, this will be 1.

ATE < - Flag for Electrical area.

ATEscripts < - Just a Yes/no input.

ATEengineer <- user login

ATEdatetimestamp <- Date.Now()

FAT < - Flag for functional.

FATscripts

FATengineer

FATdatetimestamp

SYSTEMS < - Flag for systems.

SYSTEMSscripts

SYSTEMSengineer

SYSTEMSdatetimestamp

THANKS IN ADVANCE,

Regards,

Jesus

dearjaguerrero, ur query#01 have been confusing me.. if possible send ur page.aspx and page.aspx.cs(code file) file...

Query#2:

USER LOGIN

if r u using ASP.NET built-in authentication feature than

In the Page_Load event handler, add the following line of code:

string  UserIdValue ;
UserIdValue = Membership.GetUser().ProviderUserKey.ToString()


CURRENT system date and time

at database set ATEdatetimestamp 's default value - getdate()

Query#3:

//after updating each area signing - write these code :
string strSQL = "";
string strCon = ConfigurationManager.ConnectionStrings["ConnectionStringNAME"].ConnectionString; //"Data Source=.;Initial Catalog=NorthWind;User ID=sa";
SqlConnection con = new SqlConnection(strCon);
con.Open();
strSQL = "Select ATE, FAT, SYSTEMS From tableName Where EcoNumber = 'E001'"; //insert all selecting conditions
SqlDataAdapter sda = new SqlDataAdapter(strSQL, con);
DataTable dt = new DataTable();
sda.Fill(dt);
//i guess ur ATE, FAT, SYSTEMS and EcoReadiness - fields are bit field
if (dt.Rows[0]["ATE"].ToString() == "True" && dt.Rows[0]["FAT"].ToString() == "True" && dt.Rows[0]["SYSTEMS"].ToString() == "True")
//if all three flags are true then final flag is set to true.. so EcoReadiness flag tells u that the ECO has been completed
{
strSQL = "Update tableName Set EcoReadiness = 1 Where EcoNumber = 'E001'"; //
SqlCommand cmdUpdate = new SqlCommand(strSQL, con);
cmdUpdate.ExecuteNonQuery();
cmdUpdate.Dispose();
}

con.Close();
con.Dispose();

|||

Hello Patuary! Thank you for your reply !...

I've checked your ideas.. but is your code c# ?.. because I've got a lot of errors.. I forgot to tell that I was using Visual Basic... I tried to change some of the parts but I keep getting errors when running the app... There are a couple of questions I have regarding your code...

For the user login.. I changed a little bit your code..

Saturday, February 25, 2012

CPackage::LoadFromXML Failure

My current package and all backups of previous packages are giving me this error. Anyone got any ideas? I have 1 GB free disk space. Last OS update a month ago. Ready to reinstall SSIS.

Error 1 Error loading SanDiegoRiverside.dtsx: The connection type "FLATFILE" specified for connection manager "ExtractDenormalizedErrors" is not recognized as a valid connection manager type. This error is returned when an attempt is made to create a connection manager for an unknown connection type. Check the spelling in the connection type name. c:\visual studio 2005\projects\sandiegoriverside\sandiegoriverside\SanDiegoRiverside.dtsx 1 1

Error 2 Error loading SanDiegoRiverside.dtsx: Error loading value "<DTS:ConnectionManager xmlns:DTS="www.microsoft.com/SqlServer/Dts"><DTS:Property DTS:Name="DelayValidation">0</DTS:Property><DTS:Property DTS:Name="ObjectName">ExtractDenormalizedErrors</DTS:Property><DTS:Property DTS:Name="DTSID">{92AFE6E1-8EA4-4CE5-BDA1-" from node "DTS:ConnectionManager". c:\visual studio 2005\projects\sandiegoriverside\sandiegoriverside\SanDiegoRiverside.dtsx 1 1

Error 3 Error loading 'SanDiegoRiverside.dtsx' : The package failed to load due to error 0xC0010014 "One or more error occurred. There should be more specific errors preceding this one that explains the details of the errors. This message is used as a return value from functions that encounter errors.". This occurs when CPackage::LoadFromXML fails. . c:\visual studio 2005\projects\sandiegoriverside\sandiegoriverside\SanDiegoRiverside.dtsx 1 1


If you create a new package and then try to create a new connection managers - does it work? If not, the problem might be caused by the issue described in this thread:
http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=179671&SiteID=1
and the KB:
http://support.microsoft.com/default.aspx?scid=kb;en-us;913817|||

FYI: This was caused by Flash8 Player Installer.

Laurence

|||

We got the same in production tonight, the package have been running fine for 209 nights and have never been changed. Rerunning the package works fine, I can not reproduce the error. We are running Win2003 X64 Ent. + SQL2K5 X64 Ent SP1. SSIS and RDBMS runs on the same box.

I'm not sure I would like re-register any dll's until I know the cause. Any thoughts?

Thanks in advance!

Niklas

Started: 01:13:52 Error: 2007-03-22 01:13:52.67
Code: 0xC0010018
Source:
Description: Error loading value "<DTS:ConnectionManager xmlns:DTS="www.microsoft.com/SqlServer/Dts"><DTS:Property DTS:Name="DelayValidation">0</DTS:Property><DTS:Property DTS:Name="ObjectName">NAV_det</DTS:Property><DTS:Property DTS:Name="DTSID">{C7269043-F2DD-4AE4-A831-C4E5D0632016}</DTS" from node "DTS:ConnectionManager".
End Error
Could not load package "Import_File_To_Table.dtsx" because of error 0xC0010014.
Description: The package failed to load due to error 0xC0010014 "One or more error occurred. There should be more specific errors preceding this one that explains the details of the errors. This message is used as a return value from functions that encounter errors.". This occurs when CPackage::LoadFromXML fails.
Source:
Started: 01:13:52
Finished: 01:13:52
Elapsed: 0.188 seconds

Microsoft (R) SQL Server Execute Package Utility
Version 9.00.1399.06 for 64-bit
Copyright (C) Microsoft Corp 1984-2005. All rights reserved.

|||

I am running into the same issue as LKHall ... I am confused... How come does "This was caused by Flash8 Player Installer" FIX the issue. It does not make sense to me.

Any one knows what is the root cause for this error ?

|||I have unintalled the Flash driver and reboot my PC and I am still running into the package loading failure. Help....|||

The issue seems to be related to DLLs not being registered correctly. When you install new software (the Flash Player, for example) it may register an older or newer version of a DLL, which can can break other applications. Uninstalling may not fix the problem, as that usually does not reverse the changes to the registry.

Instead you may need to re-install the application that is failing, or re-register the DLLs indicated in the articles above.

|||

Thanks John.... Can you please be more specific on what applications (or what DLLs) i need to re-install ? Do you suggest that I need to re-install SQL 2005 again?

I have used the link above to check registry and did not see any wrong registry.

|||Yes, reinstalling SQL 2005 is one way to make sure eveything is set up correctly.|||

Reinstalling SQL 2005 is a good suggestion but any other better ideas ? I have SQL 2005 SP2 installed and reinstalling the entire software is not quite easy....

Plus, I really want to know what is the root cause behind this kind of weird behavior? Doesn't MSFT SSIS team want to know this so that they can fix it in the future SPs?

CPackage::LoadFromXML Failure

My current package and all backups of previous packages are giving me this error. Anyone got any ideas? I have 1 GB free disk space. Last OS update a month ago. Ready to reinstall SSIS.

Error 1 Error loading SanDiegoRiverside.dtsx: The connection type "FLATFILE" specified for connection manager "ExtractDenormalizedErrors" is not recognized as a valid connection manager type. This error is returned when an attempt is made to create a connection manager for an unknown connection type. Check the spelling in the connection type name. c:\visual studio 2005\projects\sandiegoriverside\sandiegoriverside\SanDiegoRiverside.dtsx 1 1

Error 2 Error loading SanDiegoRiverside.dtsx: Error loading value "<DTS:ConnectionManager xmlns:DTS="www.microsoft.com/SqlServer/Dts"><DTS:Property DTS:Name="DelayValidation">0</DTS:Property><DTS:Property DTS:Name="ObjectName">ExtractDenormalizedErrors</DTS:Property><DTS:Property DTS:Name="DTSID">{92AFE6E1-8EA4-4CE5-BDA1-" from node "DTS:ConnectionManager". c:\visual studio 2005\projects\sandiegoriverside\sandiegoriverside\SanDiegoRiverside.dtsx 1 1

Error 3 Error loading 'SanDiegoRiverside.dtsx' : The package failed to load due to error 0xC0010014 "One or more error occurred. There should be more specific errors preceding this one that explains the details of the errors. This message is used as a return value from functions that encounter errors.". This occurs when CPackage::LoadFromXML fails. . c:\visual studio 2005\projects\sandiegoriverside\sandiegoriverside\SanDiegoRiverside.dtsx 1 1


If you create a new package and then try to create a new connection managers - does it work? If not, the problem might be caused by the issue described in this thread:
http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=179671&SiteID=1
and the KB:
http://support.microsoft.com/default.aspx?scid=kb;en-us;913817|||

FYI: This was caused by Flash8 Player Installer.

Laurence

|||

We got the same in production tonight, the package have been running fine for 209 nights and have never been changed. Rerunning the package works fine, I can not reproduce the error. We are running Win2003 X64 Ent. + SQL2K5 X64 Ent SP1. SSIS and RDBMS runs on the same box.

I'm not sure I would like re-register any dll's until I know the cause. Any thoughts?

Thanks in advance!

Niklas

Started: 01:13:52 Error: 2007-03-22 01:13:52.67
Code: 0xC0010018
Source:
Description: Error loading value "<DTS:ConnectionManager xmlns:DTS="www.microsoft.com/SqlServer/Dts"><DTS:Property DTS:Name="DelayValidation">0</DTS:Property><DTS:Property DTS:Name="ObjectName">NAV_det</DTS:Property><DTS:Property DTS:Name="DTSID">{C7269043-F2DD-4AE4-A831-C4E5D0632016}</DTS" from node "DTS:ConnectionManager".
End Error
Could not load package "Import_File_To_Table.dtsx" because of error 0xC0010014.
Description: The package failed to load due to error 0xC0010014 "One or more error occurred. There should be more specific errors preceding this one that explains the details of the errors. This message is used as a return value from functions that encounter errors.". This occurs when CPackage::LoadFromXML fails.
Source:
Started: 01:13:52
Finished: 01:13:52
Elapsed: 0.188 seconds

Microsoft (R) SQL Server Execute Package Utility
Version 9.00.1399.06 for 64-bit
Copyright (C) Microsoft Corp 1984-2005. All rights reserved.

|||

I am running into the same issue as LKHall ... I am confused... How come does "This was caused by Flash8 Player Installer" FIX the issue. It does not make sense to me.

Any one knows what is the root cause for this error ?

|||I have unintalled the Flash driver and reboot my PC and I am still running into the package loading failure. Help....|||

The issue seems to be related to DLLs not being registered correctly. When you install new software (the Flash Player, for example) it may register an older or newer version of a DLL, which can can break other applications. Uninstalling may not fix the problem, as that usually does not reverse the changes to the registry.

Instead you may need to re-install the application that is failing, or re-register the DLLs indicated in the articles above.

|||

Thanks John.... Can you please be more specific on what applications (or what DLLs) i need to re-install ? Do you suggest that I need to re-install SQL 2005 again?

I have used the link above to check registry and did not see any wrong registry.

|||Yes, reinstalling SQL 2005 is one way to make sure eveything is set up correctly.|||

Reinstalling SQL 2005 is a good suggestion but any other better ideas ? I have SQL 2005 SP2 installed and reinstalling the entire software is not quite easy....

Plus, I really want to know what is the root cause behind this kind of weird behavior? Doesn't MSFT SSIS team want to know this so that they can fix it in the future SPs?

CPackage::LoadFromXML Failure

My current package and all backups of previous packages are giving me this error. Anyone got any ideas? I have 1 GB free disk space. Last OS update a month ago. Ready to reinstall SSIS.

Error 1 Error loading SanDiegoRiverside.dtsx: The connection type "FLATFILE" specified for connection manager "ExtractDenormalizedErrors" is not recognized as a valid connection manager type. This error is returned when an attempt is made to create a connection manager for an unknown connection type. Check the spelling in the connection type name. c:\visual studio 2005\projects\sandiegoriverside\sandiegoriverside\SanDiegoRiverside.dtsx 1 1

Error 2 Error loading SanDiegoRiverside.dtsx: Error loading value "<DTS:ConnectionManager xmlns:DTS="www.microsoft.com/SqlServer/Dts"><DTS:Property DTS:Name="DelayValidation">0</DTS:Property><DTS:Property DTS:Name="ObjectName">ExtractDenormalizedErrors</DTS:Property><DTS:Property DTS:Name="DTSID">{92AFE6E1-8EA4-4CE5-BDA1-" from node "DTS:ConnectionManager". c:\visual studio 2005\projects\sandiegoriverside\sandiegoriverside\SanDiegoRiverside.dtsx 1 1

Error 3 Error loading 'SanDiegoRiverside.dtsx' : The package failed to load due to error 0xC0010014 "One or more error occurred. There should be more specific errors preceding this one that explains the details of the errors. This message is used as a return value from functions that encounter errors.". This occurs when CPackage::LoadFromXML fails. . c:\visual studio 2005\projects\sandiegoriverside\sandiegoriverside\SanDiegoRiverside.dtsx 1 1


If you create a new package and then try to create a new connection managers - does it work? If not, the problem might be caused by the issue described in this thread:
http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=179671&SiteID=1
and the KB:
http://support.microsoft.com/default.aspx?scid=kb;en-us;913817|||

FYI: This was caused by Flash8 Player Installer.

Laurence

|||

We got the same in production tonight, the package have been running fine for 209 nights and have never been changed. Rerunning the package works fine, I can not reproduce the error. We are running Win2003 X64 Ent. + SQL2K5 X64 Ent SP1. SSIS and RDBMS runs on the same box.

I'm not sure I would like re-register any dll's until I know the cause. Any thoughts?

Thanks in advance!

Niklas

Started: 01:13:52 Error: 2007-03-22 01:13:52.67
Code: 0xC0010018
Source:
Description: Error loading value "<DTS:ConnectionManager xmlns:DTS="www.microsoft.com/SqlServer/Dts"><DTS:Property DTS:Name="DelayValidation">0</DTS:Property><DTS:Property DTS:Name="ObjectName">NAV_det</DTS:Property><DTS:Property DTS:Name="DTSID">{C7269043-F2DD-4AE4-A831-C4E5D0632016}</DTS" from node "DTS:ConnectionManager".
End Error
Could not load package "Import_File_To_Table.dtsx" because of error 0xC0010014.
Description: The package failed to load due to error 0xC0010014 "One or more error occurred. There should be more specific errors preceding this one that explains the details of the errors. This message is used as a return value from functions that encounter errors.". This occurs when CPackage::LoadFromXML fails.
Source:
Started: 01:13:52
Finished: 01:13:52
Elapsed: 0.188 seconds

Microsoft (R) SQL Server Execute Package Utility
Version 9.00.1399.06 for 64-bit
Copyright (C) Microsoft Corp 1984-2005. All rights reserved.

|||

I am running into the same issue as LKHall ... I am confused... How come does "This was caused by Flash8 Player Installer" FIX the issue. It does not make sense to me.

Any one knows what is the root cause for this error ?

|||I have unintalled the Flash driver and reboot my PC and I am still running into the package loading failure. Help....|||

The issue seems to be related to DLLs not being registered correctly. When you install new software (the Flash Player, for example) it may register an older or newer version of a DLL, which can can break other applications. Uninstalling may not fix the problem, as that usually does not reverse the changes to the registry.

Instead you may need to re-install the application that is failing, or re-register the DLLs indicated in the articles above.

|||

Thanks John.... Can you please be more specific on what applications (or what DLLs) i need to re-install ? Do you suggest that I need to re-install SQL 2005 again?

I have used the link above to check registry and did not see any wrong registry.

|||Yes, reinstalling SQL 2005 is one way to make sure eveything is set up correctly.|||

Reinstalling SQL 2005 is a good suggestion but any other better ideas ? I have SQL 2005 SP2 installed and reinstalling the entire software is not quite easy....

Plus, I really want to know what is the root cause behind this kind of weird behavior? Doesn't MSFT SSIS team want to know this so that they can fix it in the future SPs?