SqlDataSource Selecting/Selected Events Not Firing
Nov 21, 2006
Hi,
I have a SqlDataSource and am trying to establish if it returns rows using the selected event e.AffectedRows statement. Unfortunately the selected event does not fire.
I am using a stored procedure with 2 parameters:
applicantID - Int32 - Parameter source from control label text
When I handle a event for selecting to change the value of a parameter it does not use the new value and the selected event is never called. What am I doing wrong?
Using Sql server 2005, SQLdatasource, I need to display total rows count. But the selected event is not fired? Am I mssing something or doing something wrong? Please comment. thanks Code<asp:SqlDataSource ID="DataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:AuditToolConnection%>" ProviderName="System.Data.SqlClient"SelectCommandType="StoredProcedure" SelectCommand="usp_Dashboard_GetAll" > -------------------------------- public in recordCount = 0;protected void DataSource1_Selected(object sender, SqlDataSourceStatusEventArgs e) { recordCount = e.AffectedRows; lblCount.Text += recordCount.ToString(); }
I am trying to set up a package with a built-in auditing. It has a OnPreExecute, OnPostExecute and OnError event handlers. I am trying to record when the package starts, completes, and the completion status. Each one of these event handlers has a script task that does the logging. I put in debug message boxes into each event handler script to understand what goes on. So here's the sequence of events:
1. When starting the package the OnPreExecute event fires. Right away it fires the second time. I'm guessing what happens here is the script task within the event handler fires its own OnPreExecute event - that's how the first message really pops up. The second message is generated by the actual package-level OnPreExecute event.
2. I have a condition within the OnPreExecute event handler which might set the task status to failure. You would expect the OnError handler to fire, right?.. Wrong! The package dies without firing either OnError or OnPostExecute event....
3. If i remove the condition in step 2, and force an error in the package body, i get an OnError event, and then 2 OnPostExecute events ( i guess for the same reason as in step 1).
What I'm trying to understand is why in the world my OnPreExecute and OnPostExecute events get fired by their own event handlers, yet when i fire other events within these event handlers the appropriate (other) event handler does not run.
Have written a dll that has a number of mthds to create, start, stop, list, etc... a filesystemwatcher. The dll attaches to sql fine. The dll creates it's own eventlog scope (which does showup in the event log browser dialog). So I do know it is being instantiated...
can start a watcher, can list all watchers running...in listing them i call directly down into a hidden class that houses the FileSysWat object. The listing queries some properties of the FileSysWatcher object directly so I can see if it is truely running or not (aka: EnableRaisingEvents property, path property, subdirs property, etc...)
The dll is currently configured to write to the event log, AND fire a stored procedure in ea. callback...This is not working!!! Am never getting the EventLog Record nor the SP to fire...not exceptions being thrown...NOTHING!!!!
When I open a filemgr window and go into the directory being monitored, perhaps I'll rename a file, the FileSysWatcher isn't firing the registered callback (aka: fsw.Created += new System.IO.FileSystemEventHandler(somemthdhere))
The property EnableRaisingEvents is true.
Perhaps something unusual about being inside of the SqlServer.exe process I'm unaware of!?
any ideas or help would be great!!! Tried lots of different code config's...but callback's are not being called!!!
Again...I've wired up all avail callbacks: Created, Renamed, Deleted, Error. Nothing is Firing!!!
Am not setting any NotifyFilter bits (flags) as the ctor default(s) are fine for my needs...
I know how to get the events that start say on May, and I know how to get the events that end on May, however, How would I get the events that start on January and end in July. The month of May should display that event too. so far, as an example, I have: SELECT Events.startDate, Events.endDate
FROM Events WHERE Events.Active = 1 AND startDate BETWEEN convert(smalldatetime, '5/1/2006') AND convert(smalldatetime, '5/31/2006')
I have a datasource on my page, not connected to anything. In the selected event, I have the following:protected void InitializedDatasource_Selected(object sender, SqlDataSourceStatusEventArgs e) {int total = e.AffectedRows; lblInitialized.Text = total.ToString(); } Howevever, because it's not attached to a gridview or anything, it seems the selected event never fires. How would i get it to run on page load?
Hi All - I've got a simple gridview/sqldatasource page, but the sqldatasource_onSelected event isn't firing. heres the parameters <SelectParameters> <asp:QueryStringParameter Name="LicenceID" QueryStringField="LicenceID" Type="string" /> <asp:QueryStringParameter Name="SiteID" QueryStringField="SamplingSiteID" Type="string" /> </SelectParameters>
either or both parameters may be null (ie. not in querystring ) . If only one of the selectparameters is null, and I remove it, the event fires!!! The parameters in the stored proc are optional(ie. default = NULL) and it works fine if I test it in SQL . Whats going on? If there's some error happening, why no error raised? if there are no records returned, the onselected event should still fire shouldn't it? Geoff
Hi, I have a SqlDataSource whose select statement uses parameters from the selected row on a gridview on the page. So when a row is selected in the gridview, I want the SqlDataSource to do a select using the new parameters, and then I want to inspect the number of rows returned. If 0, I want to set a FormView to insert mode, if >0 I want to set the FormView to edit mode. The "SqlDataSource2_Selected" sub never fires, so I cannot retrieve the number of rows returned. How can I deal with this? I would like the SqlDataSource to execute a Select each time the Gridview selected row changes. What could prevent "OnSelected" from firing? I do have "OnSelected="SqlDataSource2_Selected" within the SqlDataSource tag. Thanks in advance for any help with this.
Hi In the page load of my webpage I call a databind for a gridview. It generally calls this event handler : protected void SqlDataSource1_Selected(object sender, SqlDataSourceStatusEventArgs e)
However sometimes (seemingly randomly) it doesn't. Any ideas? Thanks p
Not sure if this is the correct forum, but I 'm having problems retrieving a sqldatasource's asp:control parameter values from a selected row (during edit) in a gridview to update a record thru a stored procedure. The stored procedure is pretty intense, so I'd like to keep it in SQL if possible instead of creating the generic "update table set ..." that I see in most examples. It seems as if I can't get the propertyname right or something because it keeps giving me a "Procedure or function XX has too many arguments specified error". Maybe the DataKeyNames is not right?? I've tried just passing one parameter (ProductID-same as DataKeyNames) using "SelectedValue" as propertyname and still get the same. It's got to be something very simple, but I'm at a loss. All parameters are spelled the same in the sp (with an added "@" at start) as in the asp:controlparameters. Here's the gridview (asp.net 2.0 connecting to SQL Server 2005): <asp:GridView ID="gvLoadEditProductPrices" runat="server" AutoGenerateColumns="False" AllowSorting="True" DataSourceID="SqlDataSource1" DataKeyNames="ProductID"> <Columns> <asp:CommandField ShowEditButton="True" /> <asp:BoundField DataField="ProductID" HeaderText="ProductID" HeaderStyle-BackColor="white" InsertVisible="False" ReadOnly="True" SortExpression="ProductID" /> <asp:BoundField DataField="Product" HeaderText="Product" SortExpression="Product" ReadOnly="True" /> <asp:BoundField DataField="ProductCat" HeaderText="ProductCat" SortExpression="ProductCat" ReadOnly="True" /> <asp:BoundField DataField="VarRate" HeaderText="VarRate" SortExpression="VarRate" /> <asp:BoundField DataField="loadid" HeaderText="loadid" InsertVisible="False" ReadOnly="True" SortExpression="loadid" /> <asp:BoundField DataField="loadamount" HeaderText="loadamount" SortExpression="loadamount" ReadOnly="True" /> <asp:BoundField DataField="ProductCol" HeaderText="ProductCol" SortExpression="ProductCol" ReadOnly="True" /> <asp:BoundField DataField="PageID" HeaderText="PageID" SortExpression="PageID" ReadOnly="True" /> </Columns> </asp:GridView> and the sqldatasource's info: <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:MARSProductEditor %>" ProviderName="System.Data.SqlClient" SelectCommand="spGetLoadEditProductPrices" SelectCommandType="StoredProcedure" UpdateCommand="spUpdateProductPrices" UpdateCommandType="StoredProcedure" > <UpdateParameters> <asp:ControlParameter Name="ProductID" Type="Int32" ControlID="gvLoadEditProductPrices" PropertyName=SelectedDataKey.Values("ProductID")></asp:ControlParameter> <asp:ControlParameter Name="LoadID" Type="Int32" ControlID="gvLoadEditProductPrices" PropertyName=SelectedDataKey.Values("LoadID")></asp:ControlParameter> <asp:ControlParameter Name="PageID" Type="Int32" ControlID="gvLoadEditProductPrices" PropertyName=SelectedDataKey.Values("PageID")></asp:ControlParameter> <asp:ControlParameter Name="ProductCol" Type="Int32" ControlID="gvLoadEditProductPrices" PropertyName=SelectedDataKey.Values("ProductCol")></asp:ControlParameter> <asp:ControlParameter Name="NewRate" Type="Double" ControlID="gvLoadEditProductPrices" PropertyName=SelectedDataKey.Values("NewRate")></asp:ControlParameter> </UpdateParameters> <SelectParameters> <asp:ControlParameter ControlID="ddlEstLoadsPerAcre" Name="LoadID" PropertyName="SelectedValue" Type="Int32" /> <asp:ControlParameter ControlID="txtEditType" Name="PageName" PropertyName="Text" Type="String" /> </SelectParameters> </asp:SqlDataSource>
HiI have a table in my database called 'tblUsers'It contains usernames and a few columns of data.One of them in 'birthday'it is in the format dd/mm (ie 28/04 is 28th of april)it is always 5 characters longIts data type is char in my db.Now I try this<asp:SqlDataSource ID="SqlDataSource8" runat="server" ConnectionString="<%$ ConnectionStrings:IntranetConnectionString %>" SelectCommand="SELECT DisplayName FROM [tblUsers] WHERE ([Birthday] = @ShortDate)"> <SelectParameters> <asp:ControlParameter ControlID="Calendar1" Name="ShortDate" PropertyName="SelectedDate" Type="string" /> </SelectParameters> </asp:SqlDataSource>where the selected date from a calendar control is used.Now it works when the table has a Date column which is off type DateTime but how would I modify it to work like I want?Thanks!
I facing a problem when i want to modified the sqldatasource.filterExpression while trigger sqldatasource.selecting event. 1 Protected Sub SqlDsProduct_Selecting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.SqlDataSourceSelectingEventArgs) 2 Dim SqlDsProduct As SqlDataSource = CType(CompleteGridView1.DetailRows(0).FindControl("SqlDsProduct"), SqlDataSource) 3 SqlDsProduct.FilterExpression = Session("filter") ' filter i add up after user press search button 4 End subActually i'm using the CompleteGridview, which i downloaded from the web. the "SqlDsProduct" i reffering to is inside the CompleteGridView1. I'm using complet grid view because i want the hierarchy look for the gridview. So please help me how i gonna change the filter expression of the 2nd sqldatasource inside detailsTemplate of the completeGridview. Thank you. best regardvince
Hello experts. I have been searching for anything about this but found very little. What are the events logged in SQL Server Error Logs aside from Successful/Failed Login, Backup/Restore/Recover database and, start/init sql server? Can we configure this to log other events, like CREATE or DBCC events for example? If so, how? Thanks a lot.
Using SSRS 2008 r2...I have a report with a single-value parameter and three multi-value parameters, Class1, Name2 and Name3. I'm hoping for an explanation to one thing that I'm seeing and information on a second thing.
Class1 and Name2 both have the (Select All) parameter selected but Class1 is displaying the concatenated parameter variable list whereas Name2 is showing Null. Why is that? If anything, how can I get Class1 to be similar to Name2 and show Null?But my desired wish is to have Class1, Name2 and Name3 display the text"All Selected" when the parameter (Select All) is chosen.
I have created a Transactional Replication Publication on my SQL 2012 server.When I log into another server on the domain running 2008R2 and try to subscribe to the 2012 Publication, I get the following error when clicking on "Add SQL Server Subscriber": "The selected Subscriber does not satisfy the minimum version compatibility level of the selected publication"
The 2012 DB is set as 2008 Compatibility Mode?Am I not able to Publish from 2012 to 2008?.I was using SSMS 2008 to connect to my 2012 Instance, thats why it didn't work...
I have a trigger on a table that just updates a last_modified_date and this works fine on our production server. Now I have to update some data and I do not want the trigger to fire. I cannot disable or drop the trigger because the productions systems needs the trigger. Anyone an idea of how to solve this problem?
I've got a big problem that I'm trying to figure out: I have an address table out-of-which I am trying to select mailing addresses for companies UNLESS a mailing address doesn't exist; then I want to select the physical addresses for that company. If I get multiple mailing or physical addresses returned I only want the most recently edited out of those.
I don't need this for an individual ID select, I need it applied to every record from the table.
My address table has some columns that look like: [AddressID] [int] [LocationID] [int]
AddressID is a primary-key non-null column to the address table and the LocationID is a foreign key value from a seperate Companies table. So there will be multiple addresses to one LocationID, but each address will have it's own AddressID.
How can I do this efficiently with perfomance in mind???
I would like to AUTOMATICALLY count the event for the month BEFORE today
and
count the events remaining in the month (including those for today).
I can count the events remaining in the month manually with this query (today being March 20):
SELECT Count(EventID) AS [Left for Month], FROM RECalendar WHERE (EventTimeBegin >= DATEADD(DAY, 1, (CONVERT(char(10), GETDATE(), 101))) AND EventTimeBegin < DATEADD(DAY, 12, (CONVERT(char(10), GETDATE(), 101))))
Could anyone provide me with the correct syntax to count the events for the current month before today
and
to count the events remaining in the month, including today.
I cannot get this event to fire. I am using TextBox9 to see if statements are processed and it never fills so it appears the Button4_Click never happens. Any ideas? Thank you, <asp:Button ID="Button4" runat="server" OnClick="Button4_Click" Text="Delete Submission" /> protected void Button4_Click(object sender, EventArgs e) { string CompanyDeleteID = TextBox10.Text; SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["localhomeexpoConnectionString2"].ConnectionString); SqlCommand cmd = new SqlCommand("DeleteSubmission", con); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@C_ID", CompanyDeleteID); TextBox9.Text = "SP completed"; }
PROCEDURE dbo.DeleteSubmission @C_ID intASBEGIN DELETE FROM tblCompanyInfo_Submit WHERE C_ID = @C_ID DELETE FROM tblStoreStudioSubmit WHERE C_ID = @C_ID DELETE FROM tblContractorSubmit WHERE C_ID = @C_ID RETURNENDWHERE CD_ID = @C_IDRETURN
Does anyone here know of a way to execute a DTS package from an ASP that works? I have been using a variation on Microsoft's example that has yet to work.
I know that this code is getting a handle to both the package object and the task object because it recognizes if I have them spelled incorrectly and gives me an error.
On the other hand when everything is correct it simply claims to execute but nothing really happens... My screen will read Executing... Done.
The script goes something like this, any suggestions?:
Const DTSReposFlag_Default = 0 Const DTSReposFlag_UseTrustedConnection = 256 Dim oPackage, strResult Dim oPump Set oPackage=Server.CreateObject("DTS.Package") oPackage.LoadFromSQLServer "hoaorg10","","",DTSReposFlag_UseTrustedConnection ,"","","","DirCopy" set oPump = oPackage.Tasks("Copy Data from Results to [lhr2000].[dbo].[Households] Task").CustomTask oPump.SourceSQLStatement = "SELECT * FROM HOREFPA WHERE NEIGHBORHOOD = 'testnbhd'" oPackage.Execute Response.Write "Executing package...<BR>" For i = 1 To oPackage.Steps.Count If oPackage.Steps(i).ExecutionResult = DTSStepExecResult_Failure Then oPackage.Steps(i).GetExecutionErrorInfo lpErrorCode iStatus = False strErr = oPackage.Steps(i).Name + " in the " + oPackage.Description + " failed.<BR>" End If Response.Write strResult Next If iStatus = True Then strResult = oPackage.Description + " Successful<BR>" Response.Write strResult End If Response.Write "Done.<BR>"
Anyone got an idea why this does not work. I have a trigger that is supposed to fire as an INSERT is done on a table. If I manually insert (insert into....), the trigger fires. If I use BCP to insert, the trigger DOES NOT FIRE.....
My working environment exist of Win 2000 advance server w/service pack 1 and SQL 2000 Enterprise no service pack applied.
I created trigger on INSERT table "A" which have to insert record into table "B". The trigger fired when records inserted by insert statement from Query Analyzer. But the trigger doesn't s not fired if I moved records from text file into table "A" using DTS Import/Export Wizard.
OK, I'm at a loss..it must be staring me right in the face.
I have a junction table that relates 2 tables, with a unique key of the composit of the 2 keys. There is also an indicator that says 1 relationship between the 2 tables is "primary" and there should only be one of those. So I figured a trigger to take care of it...but I can't seem to get it working...I wrote sample sql to mimic the inserted table as well, and it seems correct, but the trigger just does not fire.
Any ideas?
CREATE TABLE [dbo].[PIF_MEP99] ( [PIFRecID] [int] NOT NULL , [MEPRecID] [int] NOT NULL , [PrimaryInd] [char] (1) NOT NULL ) ON [PRIMARY] GO
ALTER TABLE [dbo].[PIF_MEP99] WITH NOCHECK ADD CONSTRAINT [PIF_MEP99_PK] PRIMARY KEY CLUSTERED ( [PIFRecID], [MEPRecID] ) ON [PRIMARY] GO
INSERT INTO PIF_MEP99(PIFRecID, MEPRecID, PrimaryInd) SELECT 1,1,'Y' UNION ALL SELECT 2,1,'N' UNION ALL SELECT 3,2,'N' GO
CREATE TRIGGER dbo_PIF_MEP99_tr_Rule1 ON dbo.PIF_MEP99 FOR UPDATE, DELETE AS SET NOCOUNT ON
-- Rule 1: Prevent and MEP from having more than 1 PIF as Primary
IF Exists ( SELECT * FROM inserted i INNER JOIN PIF_MEP99 p ON i.MEPRecID = p.MEPRecID AND i.PrimaryInd = 'Y' AND p.PrimaryInd = 'Y') BEGIN ROLLBACK TRAN RAISERROR 500003 'Attempting to Insert 2 Primary PIFs for an MEP' END GO
SELECT * FROM PIF_MEP99 GO
SELECT * FROM (SELECT 4 AS PIFRecID,1 AS MEPRecID,'Y' AS PrimaryInd) AS i INNER JOIN PIF_MEP p ON i.MEPRecID = p.MEPRecID AND i.PrimaryInd = 'Y' AND p.PrimaryInd = 'Y' GO
BEGIN TRAN INSERT INTO PIF_MEP99 (PIFRecID, MEPRecID, PrimaryInd) SELECT 4,1,'Y' COMMIT TRAN GO
SELECT * FROM PIF_MEP99 GO
SELECT * FROM (SELECT 5 AS PIFRecID,1 AS MEPRecID,'Y' AS PrimaryInd) AS i INNER JOIN PIF_MEP p ON i.MEPRecID = p.MEPRecID AND i.PrimaryInd = 'Y' AND p.PrimaryInd = 'Y' GO
DROP TABLE PIF_MEP99 GO
Brett
8-)
Hint: Want your questions answered fast? Follow the direction in this link http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx
I have a job that fires every 15 minutes. Job is working. I looked in here select * from msdb.dbo.sysmail_allitems records are in here...
I looked in here and select * from msdb.dbo.sysmail_log it says the database mail is 2008-06-24 14:46:10.997DatabaseMail process is started 2008-06-24 14:56:13.453DatabaseMail process is shutting down Which it seems to do periodically ....through out the log
What starts up the process - to go run the email alerts.
I have build a SQL Trigger that fires on the update of a specific column; this works perfectly when I test using SQL or even the SQL Server GUI but when I do the update from .NET it doesn€™t fire.
I have a dataset that gets modified and then I call sqlDataAdapter.Update(Dataset) - the row is successfully modified in the database but alas - the trigger isn't fired.
The foreach loop below runs fine and it sends emails as expected but the SP does not update the Companies table. Any thoughts? How do I cause the SP to execute? PROCEDURE newdawn.EmailSentDate @CID intAS UPDATE Companies SET Companies.LastEmailDate = (GetDate()) WHERE tblCompanies.C_ID = @CID RETURN foreach (GridViewRow row in GridView3.Rows) { pstrTo = row.Cells[2].Text; CEmail = row.Cells[2].Text; CName = row.Cells[3].Text; CID = row.Cells[1].Text; CState = TextBox1.Text; CCity = row.Cells[5].Text; CCat = row.Cells[4].Text; CCID = row.Cells[0].Text; SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["localhomeexpoConnectionString2"].ConnectionString); SqlCommand cmd = new SqlCommand("EmailSentDate", con); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@CID", CCID); try { System.String mailServerName = "mail.domain.com"; REST of code sends email to email address found in each row ....it all works find but SP above does not fire.
Someone please help me with this. I'm trying to fire off an already created DTS package. This package is stored within SQL Server's -- underneith the Data Transformation Services / Local Packages section. HOW CAN I FIRE THIS OFF FROM A VB .NET APPLICATION I'm familiar with strored procedures and using them in vb.net so if somone could lead me down that road I would be very much appriciated. Thanks in advance everyone, RB
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