EntityDataSource Null Update Parameters Not Getting Marked Modified
Feb 24, 2011
I am using an EntityDataSource with a FormView on VB.NET application. The FormView contains an AjaxControlToolKit TabContains with multiple tabs. Due to the fact that each tab is a naming container, Bind doesn't work properly for updating values (as discovered from reading other posts on stackoverflow). I instead have to declare UpdateParameters on my EntityDataSource. Example markup is as follows:
This works great, until a customer is edited and their name is set to nothing (assuming in this case, a null name is allowed). The Name UpdateParameter is set to Null but the ObjectStateEntry is not set to modified for Null properties, even if previously the Entity had a value specified. As long as the name is changed to something other than Null, everything is updated correctly.
I found a workaround by putting the following code in the Updating event of the EntityDataSource.
Dim ose As ObjectStateEntry = context.ObjectStateManager.GetObjectStateEntry(action)
For Each p As Parameter In eds.UpdateParameters
ose.SetModifiedProperty(p.Name)
Next
This makes sure that each property in the UpdateParameters has its state set to modified. It works, but it seems like a hack and I can see it causing problems down the road. Is there anything else I could do?
I have a FormView which is bound to an SQLDataSource. When a user clicks on a save button the form, I need to write any changes made to the FormView back to the table.
I have a Stored Procedure on my MSSQL 2005 database that should be executed when the user clicks on the save button.
It appears the Update is firing, but when I trap the DbCommand object in the SQLDataSource's 'Updating' event, all of the parameters that should be passed to the Stored Procedure are coming through as NULLs. Consequently, the Stored Procedure isn't updating anything.
In the click event of the save button I'm explicitly firing the SQLDataSource's Update method:
[Code]....
The parameters in the SQLDataSource <UpdateParameters></UpdateParameters> section appear to be correct.
Can anyone give me an idea on what to investigate to figure out why it appears the Update is only picking up NULLs?
here is my code for selectiong some records from db table
string strSql = "select * from mtblNBD where SentTo=@SentTo and InternalStatus Is NULL order by DeadLine desc"; SqlCommand com = new SqlCommand(strSql, con); com.Parameters.Add("@SentTo", SqlDbType.NVarChar, 50).Value = (string)Session["uname"];
here I am using parameters for SenTo field but not for NULL so it is ok... or should I use parameters for this field where value is NULL , if yes then how can I use parameter for this
I setup a very simple example using a DetailsView and an EF Model with Contact, Individual, and Customer from the AdventureWorks database (2008). Viewing, Editing, and Deleting work just fine. However, I'm getting the error when I try to create a new Contact.
Here are the relevant code snippets:
[code]...
I get the dreaded error:
Cannot insert the value NULL into column 'PasswordHash', table 'C1AdventureWorks.Person.Contact'; column does not allow nulls. INSERT fails.
I've monkeyed around with the StoreGeneratedPattern="Computed" and DefaultValue="0" for the PasswordHash property in the Contact entity as well, but it didn't .
I use calendar extender with targetID of text box. this text box is used as a parameter in EntityDataSource. now problem is that when i select the date DataSource wasn't updated. i also try it by changing the autopostback property of textbox but after postback no changes occurs and textbox is also initialize to null
A :{ id, selfId, name,} where selfId is a foreign key refered to Table A itself.
I generated the Entity automatically like this:
A :{ string id; A self; string name,} when i update the entity in gridview Edit/Update CommandField
i got the exception:
Object reference not set to an instance of an object. Description: An unhandled exception occurred during the execution of the current web request. review the stack trace for more information about the error and where it originated in the code. Exception Details: System.NullReferenceException: Object reference not set to an instance of an object. Source Error:
[Code]....
Stack Trace:
[Code]....
I guess maybe this is caused by:
A is to be updated, and when the EntityDataSource construct the new A, the reference "self" is invalid at that moment. I do not want to modify my DB structure and do not want to lose the self reference, The event EntityDataSource_Updating is not triggered while the exception hit. so i can not access my entity at any time. Maybe the worst idea is deal the whole Update Procedure myself. However, is there any better workaround?
I keep a label on the master page of my site that indicates when the site was last updated. I wanted to know if there was a quick and easy way to have the system update the date in the label everytime i compile the solution so the last updated field is always correct even if i happen to forget to update it manually.
i create the website in visual studio and make the design using Expresion web 4. now when i write some code through the visual studio on the aspx page the expression web 4 never tell about modification and update automatically itself.
Are their any way then my aspx page automatically update when i make changes or modified the page through Visual studio.
The code has two ListBoxes in fact, one a "source" and the other a "destination". As you can tell above the ListBoxes are MyList_lstAll and MyList_lstSelected. These are rendered in the browser as <select> elements, as you'd expect.
The jQuery is working great, the items are moving from one ListBox to the other, the DOM is updated but when I submit this form (not using jQuery), the ListBoxes don't reflect this change on postback.
I realize my modifications via jQuery aren't available in ViewState but I thought since the DOM was updated these changes would be part of the postback data? But in the codebehind after postback the ListBox contents haven't changed. Does anyone know what might be going on and what I can do about it?
public int deleteProduct(int ProductID, int rowid) { // Create the Database object, using the default database service. The // default database service is determined through configuration. Database db = DatabaseFactory.CreateDatabase(); DataSet productsDataSet = new DataSet();
[Code] ....
The above code am using but throwing below error how to resolve
"Update requires a valid UpdateCommand when passed DataRow collection with modified rows."
I searched a lot of threads but still couldn't get my problem fixed. I have to update the "regform" table with two fields: session_ and session2. These two fields are inside the detailview edititem template which bounded to dropdown list drpsession1, drpsession2 separately. I wanted to pass the update parameters to the update sql UPDATE dbo.regform SET session_=@session_, session2=@session2 where id=@id
the @session_ is bounded to a drpsession1 and @session2 is bounded to drpsession2. I used ControlID="ctl00$ContentPlaceHolder1$DetailsView1$drpsession1" to access the dropdown list within the detailview, but still couldn't do the updates. What's wrong with my code? Do I have to use the code behind to specify the update parameters? and How to do it? TIA.
I get an exception when deleting a row that says "Value cannot be null. Parameter Name: Original_ProductName" When I check the locals window the value is null. The ProductID has a value, but all of the other fields that are prefaced with the "original_" are null. I don't see what the issue is. I checked the bll and the gridview itself and they seem to have the necessary things. I didn't post all of the gridview and objectdatasource for brevity.
the exception listed the Original_ProductName in caps. In the code it is listed as "original_productName". This seems to be done consistently throughout so I don't think it is a capitalization issue.
i have a stored procedure to update a table. not all fields are required and some can be blank.for example, title is not required, but when it's blank i get an error
Dim ptitle As New SqlParameter("@title", SqlDbType.NVarChar, 20) ptitle.Value = objFormat.CheckSQL(title) myCommand.Parameters.Add(ptitle) ex {"Procedure or Function 'sp_UpdateUser' expects parameter '@title', which was not supplied."} System.Exception
how can i fix it so that it allows for nulls if the data field is blank?
I have a vb.net page that has an optional parameter. If a user enters data for that field, and clicks save, it saves fine via the stored procedure. HOWEVER, if the user changes their mind, and wants to erase the data they entered, they go to the text field, and delete the characters, and click save, but no matter what, the stored procedure will not save the fact that they erased the data (it won't set it back to NULL). If the user enters a space, the stored procedure will save the space, and if they enter different data, it will save the other data. I can't figure out how to get it back to letting them set it to Null? I think this is because it's an optional parameter, and the stored proc is used by several forms (Some of those forms do not include this parameter), but this form utilizes that optional paramater.
I have a "one page application" (ASP.NET 3.5, VS 2008, IE7) that uses Default.aspx as it's page, and holds an iFrame within "floating panel" (asp:Panel with extenders).
As the desired behavior is to allow users to reopen the application by refreshing the page,
I added this to the Default.aspx.cs: protected override void OnPreInit(EventArgs e) { if (!IsCallback && !IsPostBack) { Session.RemoveAll(); GeoApplication.DAL pDAL = new GeoApplication.DAL(); Session["DALinstance"] = pDAL; } }
However, when the iFrame page lifecycle starts, the Session["DALinstance"] parameter is null. I've tried to put some additional parameters and those were null as well.
I have a typical gridview/formview master control setup. When I try to update or insert I don't get any errors but it also doesn't work. When I try to insert data all I get are null values and when I update, none of the values are updated. The formview looks like its working, but just doesn't. The primary key is an identity and it auto-increments by one.
when I try to open a Music ASP.NET website from Visual Studio 2008 (Visual Web Developer) using "LOCAL IIS" option I get the message that the website is not marked as an application in IIS.
learning asp.net and prepare my final year project. i've problem in dropdownlist hope i found answer here. I've two dropdown list each consist four listitem as follows
dropdownlist1 uk,usa,india,singapore.
dropdownlist2 uk,usa,india,singapore.
if anyone of the country selected from dropdownlist1 then dropdownlist2 that particular country automatically get masked or readomly
I have been in the process of updating my code with security methods, and I've been learning this from [URL](or "Security Guidelines: ASP.NET 2.0"). In the middle of the page under "When Constructing SQL Queries, Use Type Safe SQL Parameters" it says "Use type safe parameters when constructing SQL queries to avoid possible SQL injection attacks that can occur with unfiltered input".
Now, what was to use code like:
"DataSet userDataset = new DataSet(); SqlDataAdapter myCommand = new SqlDataAdapter(LoginStoredProcedure", connection); myCommand.SelectCommand.CommandType = CommandType.StoredProcedure; myCommand.SelectCommand.Parameters.Add("@au_id", SqlDbType.VarChar, 11);........"
So, that would be how I would modify my current code base to use type safe parameters in sql updating/inserting.
Getting to my actual question, as it was said "Use type safe parameters when constructing SQL queries to avoid possible SQL injection attacks that can occur with unfiltered input". First off, that this should apply to unfiltered input. Also, in their example they only did this for an ID.
So, what I'd like to know, when it comes to "unfiltered input", does this mean as long as the input is unfiltered I must use type safe parameters, or even filtered input shall have this (just to be sure), like, input that has been ran through a regularexpression check? Shall I do this for all values I insert/update into the database, or just IDs and important things?
The way I see it right now is that it would be a good precaution to just do type safe checks on everything (literally) that updates/inserts into the database just to be extra safe. But, I really am unsure if this is really the best idea, because if I did, would this possibly cause overprocessing of information? Can this cause too much strain on server resources?