iSeller Commerce
iSeller POS Retail
iSeller POS F&B
iSeller POS Express
Crosslight
WebUI
ClientUI
What's New
Download Trial
Web Solution
Mobile Solution
Enterprise Solution
Custom Development
Blog
Community
Latest Development Blogs
ForumPostTopic
Browse By Tag
I've seen other posts in the forum about this issue, but don't see a clear solution to the problem. I've attached the web page and the SQL statement to create the table. I am using a SQLDataSource connection to connect to my database server. I'm able to Insert, Update and Delete records on the grid, but I can not, for the life of me, update a record in this very simple table. I've modified the UPDATE statement in the UpdateCommand, I've disabled the server side events... every thing and still I cannot perform a simple update statement.
Please help I've spent way to much time for such a simple problem.
Hi Ollie,
I am still unable to run the sample. I got an exection in the line below.OCMGroup.Database.Global.GetConnectionString("Mission")
So, I comment out all behind code and run your sample. When I update 'Minority' column, I got Object reference... error. I think this is the same error. When I view the source code, I found something that might be causing the issue.
Your code:
UpdateCommand="UPDATE Ethnicity SET Id = @Id, Minority = @Minority, EditUser = @EditUser, EditDate = @EditDate WHERE (Id = @Original_Id)" <UpdateParameters> <asp:Parameter Name="Id" DbType="String" Size="30" ConvertEmptyStringToNull="true" /> <asp:Parameter Name="Minority" DbType="Boolean" /> <asp:Parameter Name="EditUser" DbType="String" Size="31" ConvertEmptyStringToNull="true" /> <asp:Parameter Name="EditDate" DbType="DateTime" /> <asp:Parameter Name="Original_Id" DbType="String" Size="30" ConvertEmptyStringToNull="true" /> </UpdateParameters>
I think the correct parameter should return from SQL is "Id" instead of "Original_Id". Sometimes this happens in Sql because their conflict detection is not running.When I changed the code, I can update without face the error.
My Code:
UpdateCommand="UPDATE Ethnicity SET Id = @Id, Minority = @Minority, EditUser = @EditUser, EditDate = @EditDate WHERE (Id = @Id)" <UpdateParameters> <asp:Parameter Name="Minority" DbType="Boolean" /> <asp:Parameter Name="EditUser" DbType="String" Size="31" ConvertEmptyStringToNull="true" /> <asp:Parameter Name="EditDate" DbType="DateTime" /> <asp:Parameter Name="Id" DbType="String" Size="30" ConvertEmptyStringToNull="true" /> </UpdateParameters>
Please let me know if this works on you or not
Regards,Handy
Again, thanks for taking time to respond. It appears that declaring the Original_Id parameter in the UpdateParameters of the SQLDataSource is what is causing the Object Reference error. If I leave the statement as I originally wrote and remove the declaration, the grid works as expected. Allowing me to change key values if needed. Which is what was expected. What is confusing is that the Delete works with the Original_Id parameter declared. The @Original_Id parameter is provided by the DataSource control when you set the OldValuesParameterFormatString to "Original_{0}". This allows you access the parameter values before the change.
Thanks again.
Hi,
I am unable to run your sample because I am missing your class of object such as "OCMGroup".As far I checked, it seems the issue happened because your ID is not unique and allowed null values. The ID should not be able to change or null. Please remove it from your Update query.For testing, please try to modify only ID in your sample and refresh the grid. You will find that it is not updated. That's why if you update the other cell, it will return an error because unable to find the correct id. ID which set as PrimaryKey should be unique, cannot be changed and doesn't accept null.
Hi Handy,
Thanks for taking the time to reply to my question. I've attached the DLL to this post. As far as the Id column, it is a primary key on the table. It is identified as the key field in the WebGrid (or should be). As far changing the value of the Id field, while rare, this event does happen and that is why the Original_Id is used in the WHERE clause to let the the SqlDataSource know what value to use when is using the UPDATE statement. The database uses cascading updates and deletes so that an issue isn't opened with the IT department everytime our clients want to change the foreign key because of a typing error or business requirements. Also, I took the update to the Id column out of the statement and received the same error. Believe me, I've looked at this until I'm crossed eyed and cannot see why this is failing.
Thanks
Yes, somehow SqlDataSource returns incorrect parameter in when configure your database via wizard designer. I think maybe it is because you allow the changes for your ID. But changed the parameter as I suggested, has resolved the issue?
or
Choose this if you're already a member of Intersoft Community Forum. You can link your OpenID account to your existing Intersoft Social ID.
Choose this if you don't have an Intersoft account yet. Your authenticated OpenID will be automatically linked to your new Intersoft account.
Enter your Wordpress Blogname