Update And Delete Statement Issues
I'm working on a address book where customers can add, edit and delete address book entries. For the life of me I can't figure out what I'm messing up with the Update and Delete statements of this feature. Can someone please help me.
Here's my code:
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConflictDetection="CompareAllValues"
ConnectionString="<%$ ConnectionStrings:kalistadbConnectionString %>" DeleteCommand="DELETE FROM [Address] WHERE [AddID] = @original_AddID AND [AddNick] = @original_AddNick AND [AddFN] = @original_AddFN AND [AddLN] = @original_AddLN AND [AddCompany] = @original_AddCompany AND [AddAddress] = @original_AddAddress AND [AddCity] = @original_AddCity AND [AddProv_State] = @original_AddProv_State AND [AddPostal_Zip] = @original_AddPostal_Zip AND [AddCountry] = @original_AddCountry AND [AddPhone] = @original_AddPhone AND [CustID] = @original_CustID"
InsertCommand="INSERT INTO [Address] ([AddNick], [AddFN], [AddLN], [AddCompany], [AddAddress], [AddCity], [AddProv_State], [AddPostal_Zip], [AddCountry], [AddPhone], [CustID]) VALUES (@AddNick, @AddFN, @AddLN, @AddCompany, @AddAddress, @AddCity, @AddProv_State, @AddPostal_Zip, @AddCountry, @AddPhone, @CustID)"
OldValuesParameterFormatString="original_{0}" onselecting="SqlDataSource1_Selecting"
OnInserting="SqlDataSource1_Inserting" SelectCommand="SELECT * FROM [Address] WHERE ([CustID] = @CustID)"
UpdateCommand="UPDATE [Address] SET [AddNick] = @AddNick, [AddFN] = @AddFN, [AddLN] = @AddLN, [AddCompany] = @AddCompany, [AddAddress] = @AddAddress, [AddCity] = @AddCity, [AddProv_State] = @AddProv_State, [AddPostal_Zip] = @AddPostal_Zip, [AddCountry] = @AddCountry, [AddPhone] = @AddPhone, [CustID] = @CustID WHERE [AddID] = @original_AddID AND [AddNick] = @original_AddNick AND [AddFN] = @original_AddFN AND [AddLN] = @original_AddLN AND [AddCompany] = @original_AddCompany AND [AddAddress] = @original_AddAddress AND [AddCity] = @original_AddCity AND [AddProv_State] = @original_AddProv_State AND [AddPostal_Zip] = @original_AddPostal_Zip AND [AddCountry] = @original_AddCountry AND [AddPhone] = @original_AddPhone AND [CustID] = @original_CustID">
<SelectParameters>
<asp:Parameter Name="CustID" />
</SelectParameters>
<DeleteParameters>
<asp:Parameter Name="original_AddID" Type="Int64" />
<asp:Parameter Name="original_AddNick" Type="String" />
<asp:Parameter Name="original_AddFN" Type="String" />
<asp:Parameter Name="original_AddLN" Type="String" />
<asp:Parameter Name="original_AddCompany" Type="String" />
<asp:Parameter Name="original_AddAddress" Type="String" />
<asp:Parameter Name="original_AddCity" Type="String" />
<asp:Parameter Name="original_AddProv_State" Type="String" />
<asp:Parameter Name="original_AddPostal_Zip" Type="String" />
<asp:Parameter Name="original_AddCountry" Type="String" />
<asp:Parameter Name="original_AddPhone" Type="String" />
<asp:Parameter Name="original_CustID" />
</DeleteParameters>
<UpdateParameters>
<asp:Parameter Name="AddNick" Type="String" />
<asp:Parameter Name="AddFN" Type="String" />
<asp:Parameter Name="AddLN" Type="String" />
<asp:Parameter Name="AddCompany" Type="String" />
<asp:Parameter Name="AddAddress" Type="String" />
<asp:Parameter Name="AddCity" Type="String" />
<asp:Parameter Name="AddProv_State" Type="String" />
<asp:Parameter Name="AddPostal_Zip" Type="String" />
<asp:Parameter Name="AddCountry" Type="String" />
<asp:Parameter Name="AddPhone" Type="String" />
<asp:Parameter Name="CustID" />
<asp:Parameter Name="original_AddID" Type="Int64" />
<asp:Parameter Name="original_AddNick" Type="String" />
<asp:Parameter Name="original_AddFN" Type="String" />
<asp:Parameter Name="original_AddLN" Type="String" />
<asp:Parameter Name="original_AddCompany" Type="String" />
<asp:Parameter Name="original_AddAddress" Type="String" />
<asp:Parameter Name="original_AddCity" Type="String" />
<asp:Parameter Name="original_AddProv_State" Type="String" />
<asp:Parameter Name="original_AddPostal_Zip" Type="String" />
<asp:Parameter Name="original_AddCountry" Type="String" />
<asp:Parameter Name="original_AddPhone" Type="String" />
<asp:Parameter Name="original_CustID" />
</UpdateParameters>
<InsertParameters>
<asp:Parameter Name="AddNick" Type="String" />
<asp:Parameter Name="AddFN" Type="String" />
<asp:Parameter Name="AddLN" Type="String" />
<asp:Parameter Name="AddCompany" Type="String" />
<asp:Parameter Name="AddAddress" Type="String" />
<asp:Parameter Name="AddCity" Type="String" />
<asp:Parameter Name="AddProv_State" Type="String" />
<asp:Parameter Name="AddPostal_Zip" Type="String" />
<asp:Parameter Name="AddCountry" Type="String" />
<asp:Parameter Name="AddPhone" Type="String" />
<asp:Parameter Name="CustID" />
</InsertParameters>
</asp:SqlDataSource>
View Complete Forum Thread with Replies
Related Forum Messages:
INSERT, UPDATE, And DELETE Statement Checkbox Inactive
Hi AllgI have problem in using the SQLDataSource. When in VS 2005 I drag and drop the SQLDataSource onto my page and then add a GridView control.I bind the GridView control to the SQLDataSource control. But the problem is it does not generate the INSERT, UPDATE, and DELETE statements. The dialog box is inactive. The screenshots may help. please help me in this regard. I also tried it for Accesscontrol but the same problem. Sorry for my poor English!. thanks in advancehttp://img205.imagevenue.com/img.php?image=27550_1_122_203lo.JPGhttp://img139.a.com/img.php?image=28285_2_122_937lo.JPG
View Replies !
VS2005 - Using Detailsview To Update, Insert And Delete Rows From SQL 2005 Database. Delete And Insert Work But Update Does Not - No Errors Returned
Using VS 2005 DetailsView to insert, delete, and update rows in SQL 2005 database. insert and delete work but update does not. I recieve no errors and the detailsView comes back unchanged (as well as table row is unchanged). I am trying to use as little code behind as possible. However I do have ItemUpdating routines that seem to work (i.e Checking table for new login duplicates and encrypting passwords). The following is the source code generated by VS2005:<%@ Page Language="VB" AutoEventWireup="false" CodeFile="frmDbRegionMgrNew.aspx.vb" Inherits="frmDbRegionMgrNew" Title="Region Manager DB Update" Theme="detailsVeiwTheme" %><%@ Import Namespace="System.Data" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml" ><head runat="server"><title>Untitled Page</title> </head><body><form id="form1" runat="server"><div><asp:Label ID="Label1" runat="server" Font-Bold="True" Font-Size="Large" ForeColor="#004000"Style="z-index: 101; left: 14px; position: absolute; top: 10px" Width="199px">Data Base Maintenance </asp:Label><asp:HyperLink ID="HyperLink1" runat="server" BackColor="ActiveBorder" BorderColor="ActiveBorder"BorderStyle="Outset" Font-Bold="True" Font-Size="X-Small" ForeColor="#004000"Height="31px" NavigateUrl="DataBaseMaint.aspx" Style="z-index: 133; left: 524px;position: absolute; top: 7px" Width="96px">DB Main Menu</asp:HyperLink><br /><br /><br /><table style="width: 654px"><tr><td style="width: 120px"><asp:Label ID="Label2" runat="server" Font-Bold="True" Font-Size="Large" ForeColor="#004000"Text="Regional Manager" Width="189px"></asp:Label></td><td style="width: 100px"></td><td style="width: 203px"></td></tr><tr><td style="width: 120px" valign="top"><asp:Label ID="Label3" runat="server" Font-Bold="True" Font-Size="Small" ForeColor="#004000"Style="z-index: 128; left: 2px; position: absolute; top: 115px" Width="128px">Select Greenhouse -></asp:Label></td><td style="width: 100px" valign="top"><asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True" DataSourceID="SqlDataSource1"DataTextField="Name" DataValueField="GrnHseID"></asp:DropDownList><asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:MetrolinadataConnectionString %>"SelectCommand="SELECT [GrnHseID], [Name] FROM [Greenhouse]"></asp:SqlDataSource></td><td style="width: 203px"> <asp:DetailsView ID="DetailsView1" runat="server" AllowPaging="True" AutoGenerateRows="False"DataKeyNames="RegionMgrID" DataSourceID="SqlDataSource2" Height="50px" Width="125px"><Fields><asp:TemplateField HeaderText="RegionMgrID" InsertVisible="False" SortExpression="RegionMgrID"><EditItemTemplate><asp:Label ID="Label1" runat="server" Text='<%# Eval("RegionMgrID") %>'></asp:Label></EditItemTemplate><ItemTemplate><asp:Label ID="Label1" runat="server" Text='<%# Bind("RegionMgrID") %>'></asp:Label></ItemTemplate></asp:TemplateField><asp:TemplateField HeaderText="GrnHseID" SortExpression="GrnHseID"><EditItemTemplate><asp:Label ID="Label2" runat="server" Text='<%# Eval("GrnHseID") %>'></asp:Label></EditItemTemplate><InsertItemTemplate><asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("GrnHseID") %>'></asp:TextBox></InsertItemTemplate><ItemTemplate><asp:Label ID="Label2" runat="server" Text='<%# Bind("GrnHseID") %>'></asp:Label></ItemTemplate></asp:TemplateField><asp:BoundField DataField="DispLvl" HeaderText="DispLvl" SortExpression="DispLvl" /><asp:BoundField DataField="FName" HeaderText="FName" SortExpression="FName" /><asp:BoundField DataField="Minit" HeaderText="Minit" SortExpression="Minit" /><asp:BoundField DataField="LName" HeaderText="LName" SortExpression="LName" /><asp:BoundField DataField="Phone" HeaderText="Phone" SortExpression="Phone" /><asp:BoundField DataField="Ext" HeaderText="Ext" SortExpression="Ext" /><asp:BoundField DataField="Cell" HeaderText="Cell" SortExpression="Cell" /><asp:BoundField DataField="Email" HeaderText="Email" SortExpression="Email" /><asp:BoundField DataField="Login" HeaderText="Login" SortExpression="Login" /><asp:BoundField DataField="Password" HeaderText="Password" SortExpression="Password" /><asp:BoundField DataField="AccessLvl" HeaderText="AccessLvl" SortExpression="AccessLvl" /><asp:CommandField ShowDeleteButton="True" ShowEditButton="True" ShowInsertButton="True" /></Fields></asp:DetailsView><asp:SqlDataSource ID="SqlDataSource2" runat="server" ConflictDetection="CompareAllValues"ConnectionString="<%$ ConnectionStrings:MetrolinadataConnectionString %>" DeleteCommand="DELETE FROM [RegionMgr] WHERE [RegionMgrID] = @original_RegionMgrID AND [GrnHseID] = @original_GrnHseID AND [DispLvl] = @original_DispLvl AND [FName] = @original_FName AND [Minit] = @original_Minit AND [LName] = @original_LName AND [Phone] = @original_Phone AND [Ext] = @original_Ext AND [Cell] = @original_Cell AND = @original_Email AND [Login] = @original_Login AND [Password] = @original_Password AND [AccessLvl] = @original_AccessLvl"InsertCommand="INSERT INTO [RegionMgr] ([GrnHseID], [DispLvl], [FName], [Minit], [LName], [Phone], [Ext], [Cell], , [Login], [Password], [AccessLvl]) VALUES (@GrnHseID, @DispLvl, @FName, @Minit, @LName, @Phone, @Ext, @Cell, @Email, @Login, @Password, @AccessLvl)"OldValuesParameterFormatString="original_{0}" SelectCommand="SELECT * FROM [RegionMgr] WHERE ([GrnHseID] = @GrnHseID)"UpdateCommand="UPDATE [RegionMgr] SET [GrnHseID] = @GrnHseID, [DispLvl] = @DispLvl, [FName] = @FName, [Minit] = @Minit, [LName] = @LName, [Phone] = @Phone, [Ext] = @Ext, [Cell] = @Cell, = @Email, [Login] = @Login, [Password] = @Password, [AccessLvl] = @AccessLvl WHERE [RegionMgrID] = @original_RegionMgrID AND [GrnHseID] = @original_GrnHseID AND [DispLvl] = @original_DispLvl AND [FName] = @original_FName AND [Minit] = @original_Minit AND [LName] = @original_LName AND [Phone] = @original_Phone AND [Ext] = @original_Ext AND [Cell] = @original_Cell AND = @original_Email AND [Login] = @original_Login AND [Password] = @original_Password AND [AccessLvl] = @original_AccessLvl"><DeleteParameters><asp:Parameter Name="original_RegionMgrID" Type="Int32" /><asp:Parameter Name="original_GrnHseID" Type="Int32" /><asp:Parameter Name="original_DispLvl" Type="Int32" /><asp:Parameter Name="original_FName" Type="String" /><asp:Parameter Name="original_Minit" Type="String" /><asp:Parameter Name="original_LName" Type="String" /><asp:Parameter Name="original_Phone" Type="String" /><asp:Parameter Name="original_Ext" Type="String" /><asp:Parameter Name="original_Cell" Type="String" /><asp:Parameter Name="original_Email" Type="String" /><asp:Parameter Name="original_Login" Type="String" /><asp:Parameter Name="original_Password" Type="String" /><asp:Parameter Name="original_AccessLvl" Type="Int32" /></DeleteParameters><UpdateParameters><asp:Parameter Name="GrnHseID" Type="Int32" /><asp:Parameter Name="DispLvl" Type="Int32" /><asp:Parameter Name="FName" Type="String" /><asp:Parameter Name="Minit" Type="String" /><asp:Parameter Name="LName" Type="String" /><asp:Parameter Name="Phone" Type="String" /><asp:Parameter Name="Ext" Type="String" /><asp:Parameter Name="Cell" Type="String" /><asp:Parameter Name="Email" Type="String" /><asp:Parameter Name="Login" Type="String" /><asp:Parameter Name="Password" Type="String" /><asp:Parameter Name="AccessLvl" Type="Int32" /><asp:Parameter Name="original_RegionMgrID" Type="Int32" /><asp:Parameter Name="original_GrnHseID" Type="Int32" /><asp:Parameter Name="original_DispLvl" Type="Int32" /><asp:Parameter Name="original_FName" Type="String" /><asp:Parameter Name="original_Minit" Type="String" /><asp:Parameter Name="original_LName" Type="String" /><asp:Parameter Name="original_Phone" Type="String" /><asp:Parameter Name="original_Ext" Type="String" /><asp:Parameter Name="original_Cell" Type="String" /><asp:Parameter Name="original_Email" Type="String" /><asp:Parameter Name="original_Login" Type="String" /><asp:Parameter Name="original_Password" Type="String" /><asp:Parameter Name="original_AccessLvl" Type="Int32" /></UpdateParameters><SelectParameters><asp:ControlParameter ControlID="DropDownList1" Name="GrnHseID" PropertyName="SelectedValue"Type="Int32" /></SelectParameters><InsertParameters><asp:Parameter Name="GrnHseID" Type="Int32" /><asp:Parameter Name="DispLvl" Type="Int32" /><asp:Parameter Name="FName" Type="String" /><asp:Parameter Name="Minit" Type="String" /><asp:Parameter Name="LName" Type="String" /><asp:Parameter Name="Phone" Type="String" /><asp:Parameter Name="Ext" Type="String" /><asp:Parameter Name="Cell" Type="String" /><asp:Parameter Name="Email" Type="String" /><asp:Parameter Name="Login" Type="String" /><asp:Parameter Name="Password" Type="String" /><asp:Parameter Name="AccessLvl" Type="Int32" /></InsertParameters></asp:SqlDataSource> </td></tr><tr><td style="width: 120px"></td><td style="width: 100px"></td><td style="width: 203px"></td></tr></table></div></form></body></html>Appreciate any and all help!Dave
View Replies !
Help With Delete Statement/converting This Select Statement.
I have 3 tables, with this relation: tblChats.WebsiteID = tblWebsite.ID tblWebsite.AccountID = tblAccount.ID I need to delete rows within tblChats where tblChats.StartTime - GETDATE() < 180 and where they are apart of @AccountID. I have this select statement that works fine, but I am having trouble converting it to a delete statement: SELECT * FROM tblChats c LEFT JOIN tblWebsites sites ON sites.ID = c.WebsiteID LEFT JOIN tblAccounts accounts on accounts.ID = sites.AccountID WHERE accounts.ID = 16 AND GETDATE() - c.StartTime > 180
View Replies !
Multiple Tables Used In Select Statement Makes My Update Statement Not Work?
I am currently having this problem with gridview and detailview. When I drag either onto the page and set my select statement to pick from one table and then update that data through the gridview (lets say), the update works perfectly. My problem is that the table I am pulling data from is mainly foreign keys. So in order to hide the number values of the foreign keys, I select the string value columns from the tables that contain the primary keys. I then use INNER JOIN in my SELECT so that I only get the data that pertains to the user I am looking to list and edit. I run the "test query" and everything I need shows up as I want it. I then go back to the gridview and change the fields which are foreign keys to templates. When I edit the templates I bind the field that contains the string value of the given foreign key to the template. This works great, because now the user will see string representation instead of the ID numbers that coinside with the string value. So I run my webpage and everything show up as I want it to, all the data is correct and I get no errors. I then click edit (as I have checked the "enable editing" box) and the gridview changes to edit mode. I make my changes and then select "update." When the page refreshes, and the gridview returns, the data is not updated and the original data is shown. I am sorry for so much typing, but I want to be as clear as possible with what I am doing. The only thing I can see being the issue is that when I setup my SELECT and FROM to contain fields from multiple tables, the UPDATE then does not work. When I remove all of my JOIN's and go back to foreign keys and one table the update works again. Below is what I have for my SQL statements:------------------------------------------------------------------------------------------------------------------------------------- SELECT:SELECT People.FirstName, People.LastName, People.FullName, People.PropertyID, People.InviteTypeID, People.RSVP, People.Wheelchair, Property.[House/Day Hab], InviteType.InviteTypeName FROM (InviteType INNER JOIN (Property INNER JOIN People ON Property.PropertyID = People.PropertyID) ON InviteType.InviteTypeID = People.InviteTypeID) WHERE (People.PersonID = ?)UPDATE:UPDATE [People] SET [FirstName] = ?, [LastName] = ?, [FullName] = ?, [PropertyID] = ?, [InviteTypeID] = ?, [RSVP] = ?, [Wheelchair] = ? WHERE [PersonID] = ? ---------------------------------------------------------------------------------------------------------------------------------------The only fields I want to update are in [People]. My WHERE is based on a control that I use to select a person from a drop down list. If I run the test query for the update while setting up my data source the query will update the record in the database. It is when I try to make the update from the gridview that the data is not changed. If anything is not clear please let me know and I will clarify as much as I can. This is my first project using ASP and working with databases so I am completely learning as I go. I took some database courses in college but I have never interacted with them with a web based front end. Any help will be greatly appreciated.Thank you in advance for any time, help, and/or advice you can give.Brian
View Replies !
UPDATE SQL Statement In Excel VBA Editor To Update Access Database - ADO - SQL
Hello,I am trying to update records in my database from excel data using vbaeditor within excel.In order to launch a query, I use SQL langage in ADO as follwing:------------------------------------------------------------Dim adoConn As ADODB.ConnectionDim adoRs As ADODB.RecordsetDim sConn As StringDim sSql As StringDim sOutput As StringsConn = "DSN=MS Access Database;" & _"DBQ=MyDatabasePath;" & _"DefaultDir=MyPathDirectory;" & _"DriverId=25;FIL=MS Access;MaxBufferSize=2048;PageTimeout=5;" &_"PWD=xxxxxx;UID=admin;"ID, A, B C.. are my table fieldssSql = "SELECT ID, `A`, B, `C being a date`, D, E, `F`, `H`, I, J,`K`, L" & _" FROM MyTblName" & _" WHERE (`A`='MyA')" & _" AND (`C`>{ts '" & Format(Date, "yyyy-mm-dd hh:mm:ss") & "'})"& _" ORDER BY `C` DESC"Set adoConn = New ADODB.ConnectionadoConn.Open sConnSet adoRs = New ADODB.RecordsetadoRs.Open Source:=sSql, _ActiveConnection:=adoConnadoRs.MoveFirstSheets("Sheet1").Range("a2").CopyFromRecordset adoRsSet adoRs = NothingSet adoConn = Nothing---------------------------------------------------------------Does Anyone know How I can use the UPDATE, DELETE INSERT SQL statementsin this environement? Copying SQL statements from access does not workas I would have to reference Access Object in my project which I do notwant if I can avoid. Ideally I would like to use only ADO system andSQL approach.Thank you very muchNono
View Replies !
Subquery Issues In A Select Statement
Hi there, I am pulling back records from the DB in this case to get Wheel information. I am pulling back based on user input, but also need to query a second table that contains the Price and model number from another table based on a field being pulled back in the original select. I am not sure if this makes sense, here is a working copy of the SQL I have , but it's not pretty. There must be another way of stating this statement that i am missing, can anyone give me some suggestiosn? SELECT tblMacPak2.*, (SELECT ListPrice FROM tblMacPakPrices WHERE WheelId = OEMWheel) AS ListPrice, (SELECT PartNumber FROM tblMacPakPrices WHERE WheelId = OEMWheel) AS PartNumber FROM tblMacPak2 WHERE (Make = N'honda') AND (Model = N'civic') AND (SubModel = N'standard') AND (YearRange = N'2006') AND (Factory_Wheel_Diameter = N'15') 3 selects in one statement...that can't be right. Thanks,
View Replies !
Stored Procedure - Update Statement Does Not Seem To Update Straight Away
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 Replies !
Database Update Issues
I have a simple, one table, database to hold an internal telephone directory. All is working well, except for the update. If I edit a record, and for example, enter a value in a field that is blank, and then update, nothing happens! However, if i alter data that was already in that field and update, the changes take effect!!Any help with this would be gratefully received, Thanks in advance,Vern.
View Replies !
Across Server Update And Select Issues
Hello everybody. I am attempting the following relatively simple SQL. UPDATE Server.db.dbo.table1 SET Value = @Value WHERE Id IN (SELECT Id FROM table2) This update is taking up to 1 minute. However if I remove the select and replace with actual values the update is completed instantly ie UPDATE Server.db.dbo.table1 SET Value = @Value WHERE Id IN (id1, id2, id3) The select is also instant if executed in isolation. But when these two statements are combined time taken is too long Please note that the update is occurring on a different server and that table1 does contain update triggers. Any ideas on why this is happening? Cheers!
View Replies !
Help With DELETE Statement
Hello there... I'm creating a ASP.net Web Application and storing all my data in SQL database.I'm trying to create a Stored Procedure to Delete info from a table:- I have 3 tables: A, B and C: A's primary key is aID and has no foreign key B's primary key is bID and has 1 foreign key: aID (linking this table to table A); C's primary key is cID and has 1 foreign key: bID (linking this table to table B);- As you can see, all 3 tables are linked (A to B and B to C)I want to be able to DELETE all info from C only by giving aID, is this possible in SQL? I can retrieve the info easily through a SELECT statement and using an INNER JOIN (*). I also know how to do solve this by coding it in C# but I'd have to create some unnecessary variables and more than 1 Stored Procedure when it's probably possible to do all in one!* SELECT cID FROM C INNER JOIN B ON B.bID = C.bIDWHERE A.aID= whateverIf anyone knows the solution to my problem, please don't hesitate :p Thanks,SuperJB
View Replies !
Delete Statement
Hi,I would like to delete a record from a table on the condition that a corresponding ID is located in another table, ie. deleting an email message if the user ID is listed as a recipient in a recipient table etc. Here is my SQL statement: DELETE FROM id_email_message WHERE (id_message IN (SELECT id_message FROM recipients WHERE id_user = 324) AND message.id_message_status = 2) OR (id_message IN (SELECT id_message FROM message WHERE id_owner = 324 and id_message_status = 2)) The problem is the multiple select statements paired with the delete statement is too much overhead for the server and I always get a timeout server error (at least that's what I'm guessing, the error page and tracing isn't much helpful). Is there a more efficient way to do this?Thanks.Eitan
View Replies !
Sql Delete Statement
hi, i want to delete some records from my table if there is more then 150 records (it should always be max 150records, it can be less and then it shouldent delete anything), so when it goes over to 151 records i want to delete the oldest record, so i get the new record + 149 old records, is there a simple way to do this?
View Replies !
Delete Statement
I accedentally doubled the amount of records in my table using a DTS package. How can I remove the records ? I beleive they were appended to the table. What would be the syntax in the statement that I need to do this? Thanks, Mark
View Replies !
DELETE Statement
When does the DELETE statement physically deletes the records? For example, if I execute the DELETE statement and in the middle of the execution I understand that it is wrong. What will happen if I stop it? Will it delete the records partially? I think the deletion happens when the full statement is done but need an expert answer. Thank you.
View Replies !
SQL Delete Statement
Hi what do i need to add to this stmt to delete the result ? --------------- select ct_cust1_text01,ct_address,ct_cust1_text09,count(*)from TABLE_NAME group by ct_cust1_text01,ct_address,ct_cust1_text09 having count(*) > 1 --------- i have tried delete * from TABLE_NAME where (select...) not great at SQL appreciate any help...
View Replies !
Insert Row, Then Update Using Inserted Identity Issues..
hey everyone, I have the following SQL: CREATE PROCEDURE [dbo].[sp_InsertItem] @item_channel_id INT, @item_title VARCHAR(75), @item_link VARCHAR(75), @item_description VARCHAR(150), @item_long_description VARCHAR(1000), @item_date DATETIME, @item_type VARCHAR(20) AS IF (@item_type = 'article') BEGIN INSERT INTO items ( item_channel_id, item_title, item_link, item_description, item_long_description, item_date, item_type ) VALUES ( @item_channel_id, @item_title, @item_link, @item_description, @item_long_description, @item_date, @item_type ) END IF (@item_type = 'mediaItem') BEGIN DECLARE @new_identity INT DECLARE @new_link VARCHAR(100) INSERT INTO items ( item_channel_id, item_title, item_link, item_description, item_long_description, item_date, item_type ) VALUES ( @item_channel_id, @item_title, @item_link, @item_description, @item_long_description, @item_date, @item_type ) SET @new_identity = @@IDENTITY SET @new_link = @item_link + @new_identity UPDATE items SET item_link = @new_link WHERE item_id = @new_identity END GO Basically, what I am trying to do is this... IF the item type is article, insert normally... which works fine... however, if the item time is mediaItem, insert part of the item_link... (everything minus id.. eg: site.com/items.aspx?item_id=)... then once the row has been inserted, update that row, to make the link site.com/items.aspx?item_id=<new id> however, when the sql runs the mediaItem code, it leaves the item_link field blank. Why is this doing this? Thanks all!
View Replies !
Trigger On Delete Statement
Hi! I am deleting some records from the database and at the same time inserting them into a new table. I am doing all this with sql querries. How can that be done with triggers. Basically on the delete, i'd like to insert the affected records. Thanks! James
View Replies !
DELETE Statement Conflicted
Hello I am trying to delete a row from one table and I expected it to also be removed from the subsequent child tables, linked via foreign and primary keys. However, when I tried to delete a row in the first table I saw this error: DELETE FROM [dbo].[Names_DB]WHERE [LName_Name]=N'andrews' Error: Query(1/1) DELETE statement conflicted with COLUMN REFERENCE constraint 'FK_LName_Name'. The conflict occurred in database 'MainDB', table 'Category_A', column 'LName_Name'. I went to the very last table in the sequence and I was able to delete the row without problems, but it did not effect any of the other tables. Please advise. I need to make many changes in these tables, should I use a trigger instead, if so what is the code to trigger each table? I am new to triggers. Thanks Regards Lynn
View Replies !
Only One Of My SQL Delete Statement Are Firing
Hey guys... I am trying to tidy up my code a bit and have one SQL command (Sub class) to call when needing to insert, update, delete and select. I have got one class I am testing with that delete from a table support_ticket and then calls RunSQL() again to delete the corresponding tickets in Support_Reply. however it only seems to want to delete from one table at a time...as i commented out the first sql and it worked and the second fires...but if the first one is active it doesnt fire. Do anyone on the forum know why this has happened? Sub DeleteUserTicket(sender as Object, e as EventArgs) Dim strSQL1 = "DELETE FROM Support_Ticket WHERE (TicketID = " & txtticketID & ")" RunSQL(strSQL1) strSQL1 = "DELETE FROM Support_Reply WHERE (TicketID = " & txtticketID & ")" RunSQL(strSQL1) End Sub 'One class to run the sql statements for the entire page this will reduce in repetitve code as well as reduce code size Sub RunSQL(strSQL) Dim objCmd As SqlCommand Dim sqlConn = New SqlConnection(strConn) objCmd = New SQLCommand(strSQL, sqlConn) objCmd.Connection.Open() 'Check that the rows can be deleted if not then return a error. Try objCmd.ExecuteNonQuery() response.redirect("ticketsystemtest2.aspx") Message.InnerHtml = "<b>Ticket " & txtticketID & " Closed</b> <br/>" Catch ex As SqlException If ex.Number = 2627 Then Message.InnerHtml = "ERROR: A record already exists with " _ & "the same primary key" Else Message.InnerHtml = "ERROR: Could not update record, please " _ & "ensure the fields are correctly filled out <br>" & ex.Message & " " & ex.Number Message.Style("color") = "red" End If End Try objCmd.Connection.Close() sqlConn = nothing objcmd = nothing End Sub cheers
View Replies !
Tuning A Delete Statement
Hi, I need to delete the following records (from enrollment_fact): SELECT a."STU_SID", a."SCHOOL_YEAR", a."DATE_SID", a."LOC_SID" FROM "dbo"."ENROLLMENT_FEX2" b, "dbo"."LOCATION_DIM" c LEFT OUTER JOIN "dbo"."ENROLLMENT_FACT" a on c."LOC_SID" = a."LOC_SID" WHERE b."LOC_KEY" = c."LOC_KEY" and a."DATE_SID" between b."MIN_DATE" and b."MAX_DATE" This is the approach (excuse the misuse of the concat function, but you get the idea) DELETE FROM "dbo"."ENROLLMENT_FACT" WHERE CONCAT (a."STU_SID", a."SCHOOL_YEAR", a."DATE_SID", a."LOC_SID") IN ( SELECT DISTINCT CONCAT (a."STU_SID", a."SCHOOL_YEAR", a."DATE_SID", a."LOC_SID" ) FROM "dbo"."ENROLLMENT_FEX2" b, "dbo"."LOCATION_DIM" c LEFT OUTER JOIN "dbo"."ENROLLMENT_FACT" a ON c."LOC_SID" = a."LOC_SID" AND a."DATE_SID" BETWEEN b."MIN_DATE" AND b."MAX_DATE") comments? better way? (without using an sp) thanks
View Replies !
Delete Statement Using A Join Plz Help
well i have 2 table one name detcom and another entcom stored in DB1 the key for both to join on is lets say A, B, C . I need to check if there are records based on the key A, B, C of both table where C EQUALS to '80_300_113' and if there are delete them and then grab data from another database named DB2 on same server (same instance) wich contains the same tables entcom and detcom and insert all the data from those tables into the same tables in DB1 based on the key and where C = '80_300_113' PLZ help
View Replies !
Question About Delete Statement
Hi,My question is : CREATE TABLE t1 (c1 INTEGER, c2 INTEGER, c3 DECIMAL(15,0 )) INSERT INTO t1 VALUES (1, 2, 3.0) How can i define a SQL commend will cause C1 to be decremented each time a row is deleted from the T2 table? Thanks !
View Replies !
Delete Statement Won't Work!!
i am having problem running a simple delete statement against a table. it just hangs is there anything i should look at? the table has 4 primary keys and the index makes up of the 4 keys and ideas? i viewed the delete statement with the execusion plan and this is what i saw. delete -> index delete/delete -> sorting the input -> table delete/delete -> Top -> Index scan.
View Replies !
Recover After Delete Statement
One of our developers just deleted a ton of records- is there any way we can recover this data? (we can't use a backup since a ton of changes were made since we last backed up) Thanks- Jack
View Replies !
Delete Statement Very Slow
Hi, I've got a table with about 500 000 records and growing monthly by about 40 000 records When I perform the following query: DELETE from [myTable] WHERE Month = '07' AND Year='2005' This query will take about 10 minutes to execute. Columns Month & Year are both indexed. Surely MSSQL can't be this slow on only 500 000 records. Must I do some other database optimization ??? Thanks
View Replies !
Join In A Delete Statement???
Hi all, I need to do a delete statement that removes rows from table 2, where data was created before data in table 1. Here's my select statement that shows me the results that meet the criteria: Select DP_ACC.ACC_NO, DP_EVENT.EVENT, DP_ACC.CALL_DATE, DP_EVENT.EVENT_DATE1 FROM DP_ACC Inner Join DP_EVENT on DP_ACC.ACC_NO = DP_EVENT.ACC_NO Where CONVERT(DATETIME, DP_EVENT.EVENT_DATE1) < CONVERT(DATETIME, DP_ACC.CALL_DATE) How do I change this into a delete statement to remove the rows from DP_EVENT?
View Replies !
Please Help Me With A Complex DELETE Statement
Hello, currently I have a query like this: PHP Code: SELECT * FROM relations INNER JOIN paths ON relations.path = paths.path_id WHERE (paths.links = '161') AND (relations.node1 = 162) OR (paths.links = '161') AND (relations.node2 = 162) OR (paths.links = '162') AND (relations.node1 = 161) OR (paths.links = '162') AND (relations.node2 = 161) OR (paths.links LIKE '162%') AND (relations.node1 = 161) OR (paths.links LIKE '%162') AND (relations.node2 = 161) OR (paths.links LIKE '161%') AND (relations.node1 = 162) OR (paths.links LIKE '%161') AND (relations.node2 = 162) OR (paths.links LIKE '%161;162%') OR (paths.links LIKE '%162;161%') ORDER BY relations.node1 Don't pay attention to the 161 and 162 things, is just test data, now my problem is that I want to transform that into a DELETE statement, but I can't find the right way to do it, so far I managed to do something like: PHP Code: DELETE relations FROM relations INNER JOIN paths ON relations.path = paths.path_id WHERE (paths.links = '161') AND (relations.node1 = 162) OR (paths.links = '161') AND (relations.node2 = 162) OR (paths.links = '162') AND (relations.node1 = 161) OR (paths.links = '162') AND (relations.node2 = 161) OR (paths.links LIKE '162%') AND (relations.node1 = 161) OR (paths.links LIKE '%162') AND (relations.node2 = 161) OR (paths.links LIKE '161%') AND (relations.node1 = 162) OR (paths.links LIKE '%161') AND (relations.node2 = 162) OR (paths.links LIKE '%161;162%') OR (paths.links LIKE '%162;161%') But that would delete only from the relations table and not from the paths table. I need to delete from both tables. Can anyone help me please? Its kinda urgent. Thansk!
View Replies !
Delete Statement Question
I have a simple database program which uses the following statement to delete rows by a date range. In testing the SQL statement, it worked, but when using it in the VB program, it says it worked, but doesn't remove the row. I am using a local database. Please help. cmdDeletePayments.CommandType = Data.CommandType.Text cmdDeletePayments.CommandText = "DELETE Payments WHERE (CheckDate BETWEEN @BeginningDate AND @EndingDate)" cmdDeletePayments.Parameters("@BeginningDate").Value = CType(dtpBeginning.Text, Date) cmdDeletePayments.Parameters("@EndingDate").Value = CType(dtpEnding.Text, Date) Try conPayments.Open() iRows = cmdDeletePayments.ExecuteNonQuery() conPayments.Close() Catch ex As Exception MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error) End Try MessageBox.Show(iRows.ToString + " records deleted.", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information)
View Replies !
512 Error In Delete Statement
I have a piece of code that uses the db-library with sql server 2000/2005 and runs the following delete statement: DELETE FROM TABLE1 WHERE COL1 IN( 'Some Val1' ) AND COL2 IN( 'Some Val2' ) AND Col3 IN( integer1 ) AND Col4 IN( integer2 ) AND Col5 IN( 'Some Val3' ) on TABLE1, uploads data into TABLE1 through bulk loading, calls a stored procedure that uses the data, and then deletes the data through the SAME delete statement with EXACTLY the same parameter values. The first delete statement is always successful, but the second statement intermittently gives the following error: 0,0,MS SQL Server Message : SQL Server message 512, state 1, severity 16: Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, <, <= , >, >= or when the subquery is used as an expression. SQL Server message 3621, state 0, severity 0: The statement has been terminated. Note: I was initially using the equality operator instead of the IN operator in the query but that gave the same results. Can somebody tell me whats going wrong here? I can easily ignore this error because my work is done after the stored proc but I fear amassing a lot of useless data in the table over time. Also http://support.microsoft.com/kb/195491 talks about a case where the delete statement is actually successful but still causes an error when using ADO.
View Replies !
Insert And Delete In One Statement
i am creating an insert based on a select statement -- i need to delete the row from the select statment table after it has been inserted something like insert into table_insert(value1, value2) (select table_exclude_id, value1, value2 from table exclude) delete from table_exclude where table_exclude_id in "the select statement" can you do this?
View Replies !
Delete Statement In Function
Is it possible to create a function that deletes records from a table ? CREATE FUNCTION F_TSImported_Delete() returns int as Begin delete from ts_imported return 0 end GO This throws error like this: Invalid use of side-effecting or time-dependent operator in 'DELETE' within a function.
View Replies !
Very Tricky Delete Statement
I have a rather tricky SQL delete query I’m trying to perform, preferably without cursors. I have the following data set, where I want each of the first changes to the status. IDStatus 1Good 2So-So 3So-So 4Bad 5Bad 6Bad 7Bad 8Bad 9So-So 10Good So given the above data set I would want to delete the following IDs: 3, 5, 6, 7, and 8. As they not the first in order. The problem is that while I can get isolate and save first instance of each status (in this case 1, 2, and 4), I can’t get the what I want. Is there a SQL way of accomplishing this.
View Replies !
DTS Issues-Cannot Isert Or Update BLOB Data Type
Hi, Query-based insertion or updating of BLOB values is not supported. I am exporting the database from MSSQL to MySQL I get the error above, Looking for a solution to this, can anyone assist, I have tried a couple of things checking the "do not count column length" and "safe" and "large result" anyway anytime I run the query I get OLE ODBC generic connector error Query-based insertion or updating of BLOB values is not supported. But the issue is it is always using the Generic OLE Connector instead of the Mysql specific driver. Any assistance would be great I feel as though I 've had a few drinks, I guess the 14 hours on this DTS is catching up. THanks for any assistance Jack - over and out and zzzzzzzzz
View Replies !
Delete Statement With Parameters Not Working
When I debug my code I see the string going into the parameter correclty, but the the delete statement doesnt work and I'm not sure why. Does this look ok? // Set up SqlCommand, connection to db, sql statement, etc. SqlCommand DeleteCommand = new SqlCommand(); DeleteCommand.Connection = DBConnectionClass.myConnection; DeleteCommand.CommandType = CommandType.Text; // Store Primary Key photoID passed here from DeleteRows_Click // in a parameter for DeleteCommand SqlParameter DeletePrimaryKeyParam = new SqlParameter(); DeletePrimaryKeyParam.ParameterName = "@PhotoID"; DeletePrimaryKeyParam.Value = photoID.ToString(); // Insert new parameter into command object DeleteCommand.Parameters.Add(DeletePrimaryKeyParam); // Delete row, open connection, execute, close connection DeleteCommand.CommandText = "Delete From Photo_TBL where PhotoID IN (@PhotoID)"; Response.Write(DeleteCommand.CommandText); // DeleteCommand.Connection.Close(); DeleteCommand.Connection.Open(); DeleteCommand.ExecuteNonQuery(); DeleteCommand.Connection.Close();
View Replies !
Is The Sql Delete Statement Case Sensitive?
I need to delete a record from a SQL server database table. I need to target a specific column with a query that looks like the following: delete from NameTable where Name = 'Barbosa' The problem is that their are two other records with the name spelled similarly, only differing by case sensitivity. Like as follows: 'Barbosa' 'barbosa' 'BarBosa' Is sql case sensitive? Will my Sql delete statement only delete the record with the word 'Barbosa' in that column. Or will it delete all of the records with the names 'Barbosa' 'barbosa' 'BarBosa'
View Replies !
SQL Data Source Delete Statement
Hey everyone, Currently I have a problem that with a gridview delete command because the database I currently want to delete from is a PK to 1 other table. So how can I delete from that "Membership" table before I use the gridview to delete from the "Events" table? Here is a very shortened version of the tables Events EventID (PK) Membership MembershipID EventID (FK) UserID (FK) I have to delete ALL the members from the event in the membership table first before I can delete the actual Event...So how can I do that when the gridview only allows you to delete from 1 table, if I understand this correctly. Here is the sqldatasource delete command as of right now. DeleteCommand="DELETE FROM [Events_Events] WHERE [EventID] = @original_EventID" Obviously I am getting a error because of the FK. Thanks, Chris
View Replies !
Index Hint In Delete Statement?
According to what I see in BOL, the following should work: delete from dbo.tbl1 WITH (INDEX(idx_un01)) where tbl1_no = 1 Yet when I syntax check this I get: Msg 1069, Level 15, State 1, Line 2 Index hints are only allowed in a FROM clause. (Please ignore the fact that index hints are unnecessary / a bad idea / etc.)
View Replies !
Alter Statement To Delete The Default Value Set
Hi I want to delete the Default value for a specific column which is set to Null I've used ALTER TABLE SYSTEMS_PATIENT_LOG ALTER COLUMN SYSTEMS_LOGID DROP DEFAULT It is giving error Msg 156, Level 15, State 1, Line 1 Incorrect syntax near the keyword 'DEFAULT'. plz could any one tell me where I could be wrong
View Replies !
SQL Delete Statement In Relational Model
Hi, I have a large database with complex relations and I just can't figure out how to delete a single record and all its relations across database (not to mention that I can't understand why can't the DELETE statement work just like the SELECT). It would be impossible to let you know the structure through this message, but let's say that I have 5 tables in which there are relations like this (all the tables contains a unique ID for each record, but not all contains info of the main record): Production -> ProductionTypes Sales -> ProductionTypes Production -> Sales Sales -> Personnel Personnel --> Orders Orders --> Financial I hope we agree that if I delete the ProductionID.Production directly, there will be no way to know which Financial.Commission I have to delete because I just can't insert the ProductionID in every table on the database. What do I have to do ? I just couldn't find any solid information regarding this subject on the net. Many many thanks in advance ! George
View Replies !
NewBie: Problems With DELETE Statement
I am trying to delete records in a table if a flag set in a linked table is set, but seem to be having problems with it. Neither of the following work: DELETE FROM DSCar WHERE SerialNum IS NOT NULL AND DSCar.SerialNum=DSOrds.SerialNum AND DSOrds.StatusFlag='3' This reports DSOrds.SerialNum could not be bound DELETE FROM DSCar INNER JOIN DSOrds ON DSCar.SerialNum=DSOrds.SerialNum WHERE DSOrds.StatusFlag='3' This reports Incorrect syntax near the keyword 'INNER' But a similar SELECT statement works fine: SELECT * FROM DSCar INNER JOIN DSOrds ON DSCar.SerialNum=DSOrds.SerialNum WHERE DSOrds.StatusFlag='3' I think it is something simple but am having a real head scratcher. Thanks
View Replies !
Delete And Update
Hi All,I have a Access front-end,the tables are from SQL server 2000 andlinked via ODBC using DSN.I have a Main table and several related tables.The Main table has aOne -to- Many relationship with the related tables.When I try to delete a record from the front-end,I get a error msg "the table is locked,you and another user are attempting to delete/update the same record".I am the single user and I am at a loss tounderstand what the problem is.I have to explain that I never had a problem when i was using Accessas the backend too.Is it because of linking?Any suggestions?Roy
View Replies !
Update And Delete
I need to update rows in database A from data in database B and delete from database B if a match is found but leave in databse B if no match found. Is there a way do do this with the OLe DB command?
View Replies !
Single Statement To Delete Record Into More Tables
Hi , I little question for you ... is it possibile to write a SQL statement to delete records in several tables at the same time? For example if I've two tables involved by join DELETE <...> from Customers A INNER JOIN CustomerProperties B ON A.CustomerID=B.CustomerID I Must use two statement to remove records from both the tables? Thx
View Replies !
Delete Statement Times Out And Blocks Reads
Hi. Periodically I need to run a delete statement that deletes old data. The problem is that this can timeout using ODBC (via the CDatabase and CRecordSet classes in legacy code). Also, while its running the delete, the table its operating on is locked and my application can't continue to run and operate on rows not affected by the delete. Are there any workarounds for this? Can the timeout be set in the connect string? Thanks, Brian
View Replies !
|