Delete parameter getting set to NULL why?

I have datagrid whose data source is set to SqlDataSource. SqlDataSource's connection string is set dynamically at pageload. When i click on delete link in gridview it executes delete command but row doesnt get deleted from data source. When i run Sql server profiler i found the delete statement is getting executed but the parameter is always null. why?


 <asp:GridView ID="GridView1" runat="server" AllowPaging="True" AllowSorting="True"
                        Caption="Events emitted by the application." DataKeyNames="EventId" OnDataBound="GridView1_DataBound" Width="600px" OnSelectedIndexChanged="GridView1_SelectedIndexChanged" OnRowDeleting="GridView1_RowDeleting" OnRowCommand="GridView1_RowCommand">
                            <asp:BoundField DataField="EventId" HeaderText="EventId" SortExpression="EventId" />
                            <asp:BoundField DataField="EventTime" HeaderText="EventTime" SortExpression="EventTime" />
                            <asp:BoundField DataField="Message" HeaderText="Message" SortExpression="Message" />
                            <asp:CommandField SelectText="Vew Details" ShowDeleteButton="True" ShowSelectButton="True" />
                    <asp:SqlDataSource ID="SqlDataSource2" runat="server" DeleteCommand="DELETE FROM aspnet_WebEvent_Events WHERE (EventId = @EventId)"
                        SelectCommand="SELECT EventId,EventTime,Message FROM aspnet_WebEvent_Events WHERE (ApplicationVirtualPath = @ApplicationVirtualPath)">
                            <asp:ControlParameter ControlID="DropDownList2" Name="ApplicationVirtualPath" PropertyName="SelectedValue" />
                            <asp:Parameter Name="EventId" Type="String"/>                            


protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)

        protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
            if (e.CommandName == "Delete")
5/27/2008 5:20:07 PM 29906 articles. 0 followers. Follow

4 Replies

Similar Articles

[PageSpeed] 29

A person needs to use a control parameter in the datasource and an item template field in the gridview


Hope this helps



5/27/2008 8:34:41 PM

Am I missing something? Where is the attribute for gridview?  datasourceid="SqlDataSource2"

Also not sure if we need  once the datasource is set for gridview

asp:Parameter Name="EventId" Type="String"/>                           

Regards, Sreenivas (Vasu) Chaparala
ps:Unless a question, this is an attempt to provide guidance. Turning this into a solution, if required, is ones own responsibility. Expecting the entire solution as-is is inappropriate for any professional.
5/28/2008 6:01:36 AM

the datasource for gridview is set dynamically. So it think even the parameter value also i need to setup at runtime in RowDeleting event

5/28/2008 3:48:53 PM

I have datagrid whose data source is set to SqlDataSource. SqlDataSource's connection string is set dynamically at pageload. When i click on delete link in gridview it executes delete command but row doesnt get deleted from data source. When i run Sql server profiler i found the delete statement is getting executed but the parameter is always null. why?

I believe this is a page life cycle thing. If you have read the code of GridView (or BaseDataBoundControl), you may find the exact reason (however, this will cost pretty a lot of time and effort). The easist and most efficient way is to use sqldatasource instead of sqldatasourceid. As based on my knowledge, sqldatasourceid is NOT designed for you to use dynamically. If you cannot be sure of the actual datasource at compile time, use sqldatasource and call Databind() and the right time. This is the general way which is supposed to follow.

Hope my suggestion helps

Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.
6/2/2008 9:29:59 AM

Similar Artilces:

Getting a value set to Null.NullInteger to be set as Null on an SQL database
I am using the CodeSmith DNN templates and finding them great for coding.  When I set a feild in an Info class to Null.NullInteger then pass this to a controller to update, the SQL parameter value that is passed is -1 rather than Null.What's the best way to correct this?Jonathan Palmer Any news on this? I'm having the exact same problem.Juliana -1 is null for an integer. Are you wrapping the sproc argument with GetNull() in your SqlDataProvider? Best Regards, Jason The issues is when you have an integer value that can be minus - e.g. temperature in degrees and you a...

How do I get the parameter for the delete command when I get the parameter for the select in another way?
I'm working with VS 2008.  I've got a data grid control, which I populate through a DropDownList that is data bound using a stored procedure.  When the DDL changes it updates the contents in the DataView control.  The DataView control is also data bound, and is populated using its own stored procedure and the code returned from the DDL once the user selects something.  I've got another stored procedure assigned to the DeleteCommand of the SqlDataSource, which I intend to use is with a delete CommnadField of the DataView control.  However, in this case I w...

setting empty text box input on form to null parameter for sql
Hi,  I'm pretty new to ASP.NET and VB, but I'm working on a project which is essentially a staff directory. Using VS 2005, I've setup a basic grid view which connects to an object which connects via a data layer to a SQL database with Name, Surname, Email, Extension No and Department fields. I have it working so that if a user enters a name and surname for example, it will return all records with either the name matching or surname matching input parameters. What I want to do is to set up a SQL query which is:  SELECT * FROM records WHERE (Name LIKE @Name) AND (Su...

Passing SQL Parameter Array to Object datasource as parameter
I have a class 'CommonDataAccess' and my method filldataset() accepts a Stored Procedure name and a SQL Parameter Array. This class is to be made as the type for the Objectdatasource which is Bound to a gridview. How do I pass the SQL Parameter Array to this.  Raj Kiran S------------Chennai, India CALLINGBELLS: I have a class 'CommonDataAccess' and my method filldataset() accepts a Stored Procedure name and a SQL Parameter Array. This class is to be made as the type for the Objectdatasource which is Bound to a gridview. How do I pass the SQL Parameter Array to t...

Returning null, the .net client dont get null
I have a java (axis 1.4) web service, My web service return an object, but when the object is null, the .net client don't get object= null, It get object.field1=0, object.field2="" ...Where is the problem?Thankss The webservice response is this:<?xml version="1.0" encoding="utf-8"?><soapenv:Envelope xmlns:soapenv="" xmlns:xsd="" xmlns:xsi=""><soapenv:Body><getVariableAnalogicaPorConsignaRe...

DataSource returns null when using null integer parameter
Hi, I am trying to create a search page using a number of fields, mostly strings, one is an integer. That allows the user to use any combination of the fields to search with. I have a datasource configured using the (v2.0) tools and the parameters are passed from controls to a stored procedure. I have set default values for the strings to '%' and left the default for the integer blank. When i test the query in configuration it works fine with a blank integer. But when i run it in the webpage the datasource returns null if the integer field is blank. I have checked th...

On Delete Set Null
Using PD7 on Oracle 8.1.6 model. Trying to model an "On Delete Set Null" constraint for a reference using declarative integrity. It doesn't allow me to do it (grayed out). I have worked around this by dropping and re-adding the constraint in script (from the Script/End dialog of the child table) but this is clumsy. Is this a known bug? (thx for the help on the double-zero thing, by the way, that one was killing me! why couldn't I have found this newsgroup earlier?!) Click on Database->Edit Current DBMS Navigate through Script, Objects, Reference Highligh...

Reference sontsraint SQL server 2005 PDM(PD12.1) no SET DEFAULT/SET NULL
For PD12.1 I cannot select option SET DEFAULT, SET NULL as Reference constraint for a PDM for SQL server 2005. Any ideas to solve this? DM Unseen (AKA M. Evers). Sorry for the delay in responding to your question. It would appear that MS doesn't support the "ON DELETE SET NULL" and "ON DELETE SET DEFAULT" syntax. If it does, you can change your definition file (recommend you make a copy and change the copy). In the definition file, expand to: MSSQLSRV2005::Script\Objects\Reference\DclDelIntegrity The values you will see are NO ACTION, RESTRICT, CASCA...

I am working with ASP and an access database which resides on a windows server and i have been having alot of trouble with my SQL statements especially in regards to IS NOT NULL and IS NULL. below is my sql statement: It spits out everything in the database even those that do not meet the requirements: strsql="SELECT * FROM [items] WHERE (datein IS NOT NULL AND deactivatedon IS NULL AND storagecentre IS NOT NULL) ORDER BY "&strsort&""  I have tried using <> instead of IS NOT NULL but it doesnt seem to be recognised because it outputs all re...

null datasource parameter for dataview
I have a dataview that uses a textbox value as a parameter for its datasource.  If a value is entered into the textbox, data is return correctly.  If no value is entered, it returns nothing (there are no records with a null value for that field).  Instead, I would like it to return all values if the textbox is left blank.  Any ideas?...

Setting Formview Datasource Parameter
I am trying to use the code below to set a formview datasource parameter in the page_load section of a user control (ascx file): public void Page_Load(object sender, EventArgs e){     formview_datasource.SelectParameters.Add("@department_id", "e62bbc7d623f44a68e101cba90e839s3");} However I am getting the following error: Exception Details: System.Data.SqlClient.SqlException: Must declare the variable '@department_id'. So it would seem that page_load in my user control isn't being called? I'm not sure why or how to work around it....

PD EBF 4 Oracle 9i supports a foreign key with an ON DELETE SET NULL. When I look at the Oracle 9i2 DBMS it shows Script>Objects>Reference>DclDelIntegrity has 3 values (RESTRICT, CASCADE, and SET NULL), but the Integrity tab on the Reference Properties dialog will not allow SET NULL (grayed out). Is this a bug or am I missing something? For me SET NULL is only greyed out for the Update constraint. If I select Set Null under the Delete constraint section, I get the following DDL: alter table TABLE_2 add constraint FK_TABLE_2_REFERENCE_TABLE_1 foreign ...

SQL DataSource will not delete!
Hi all, I am having big problems with an SQL datasource and a DataList here. I have made my own basic GuestBook page and use a database table to store the entries. The SELECT and INSERT statements work great and all is fine with those. However, I also want to be able to delete GuestBook entries as Admin incase I get people writing abuse etc. Whatever I do, I CANNOT get the delete functionality to work. If I use QueryBuilder when configuring the DataSource it does work - but within the site, when I click the delete button, it does not work at all. Just posts back the page with the same dat...

Get SQL Error from .Net
I am sing SQL Procedures for Insert and Update. In the SQL Procedure i used try catch.  How can i get the SQL exception from .net. Try{ //Execute your sql here.}Catch  (SqlException and sqlEx){ //Do Something}   Pushing out shapes, to a popular beat combo. If you want to cause an error in the calling application you need to raise an error in the Catch Block.  If you just want to return the error information as a resultset, execute a select statement.  There are several variables, only available in the Catch Block, that you can use to ret...

Web resources about - Delete parameter getting set to NULL why? -

Parameter - Wikipedia, the free encyclopedia
A parameter (from the Ancient Greek παρά , "para", meaning "beside, subsidiary" and μέτρον , "metron", meaning "measure"), in its common meaning, ...

fb_source Parameter - Facebook-Entwickler
This document lists the complete list of values for the fb_source parameter that is returned with th...

Google Webmaster Tools Parameter Handling - Flickr - Photo Sharing!
You aren't signed in Sign In Help Home The Tour Sign Up Explore Explore Home Last 7 Days Interesting Popular Tags Calendar Most Recent Uploads ...

Cat 8: TIA performance standards committee chairman previews parameters of forthcoming twisted-pair cable ...
Category 8, the next-generation twisted-pair cabling specification, is still in development, but the outlook looks quite positive that it will ...

Philippine president asks for 'parameters' of Mayon Volcano tours
Philippine president asks for 'parameters' of Mayon Volcano tours People's Daily Online ... 26, 27, 28, 29, 30, 31. Jan, Feb, Mar, Apr, May, ...

Alternatives to boolean parameters
... ) { PrintLine ( item . Name ); if ( printDetails ) { PrintLine ( item . Description ); } } } Aha! Now can see that the boolean parameter ...

Exporting Error (Error in Parameter...: Apple Support Communities
This site contains user submitted content, comments and opinions and is for informational purposes only. Apple disclaims any and all liability ...

Apple tech monitors device aging, adjusts operating parameters to ensure optimal performance
... describing a method of monitoring the aging of a device's electronics, comparing the data with a global average and modifying operating parameters ...

Is it poor programming practice to pass parameters as objects?
... a free, community-powered network of 100+ Q&A sites . Risser asked: So, we've got a guy who likes to write methods that take Objects as parameters, ...

Parameter Short Film Competition sponsored by Grolsch
Grolsch presents Parameter The A.V. Club Short Film Competition Please Enter Your Date of Birth Ineligible entry Enter For people over the age ...

Resources last updated: 11/29/2015 8:41:33 PM