I'm using linq to sql to on a recent project. So was wondering if anyone could provide any advice as to why this code doesn't update the database? The problem seems to be that the value from the textbox isn't persisted when I click the submit button in the gridview.
[HttpPost] public ActionResult Deposit(DepositTicket dt)[code]....
Where the comment "Update Query" is, is where I want to add an update query to updated the Account table with an Account object. I want to update the exisiting record, can this be done using the predefined functions for db.Accounts or would I have to write a linq query?
I keep running into a problem when trying to connect to my web service. THe problem only occurs when I try to update the database linq to sql file. When I do this and then upload the wcf services and attempt to connect I get this error: Quote: The server did not provide a meaningful reply; this might be caused by a contract mismatch, a premature session shutdown or an internal server error.
Server stack trace: at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout) at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs) at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMess age methodCall, ProxyOperationRuntime operation) at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message) Exception rethrown at [0]: at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg) at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type) at IService1.GetPollById(Int32 pollId) at Service1Client.GetPollById(Int32 pollId)
If I then revert back to the old linq to sql file it works fine.
In my 2nd ASP.NET MVC project I'm facing a very weird problem: when I call the SubmitChanges method of the DataContext class, nothing updates in the database. It's weird because everything works fine with my first project. I'm using a remote database created in Sql Server Management Studio, I tried doing some queries there and in Visual Studio 2010 (where I have the connection to the database), they all work. Where might the problem be hidden?
DBDataContext DB = new DBDataContext(); var myuser = DB.Users.Single(u => u.ID == id); myuser.Age = 45; DB.SubmitChanges();
This is embarrassing :D Indeed I didn't have a primary key. Now it works!
I have a table with Id, Name,...IsActive, etc. If user wants to delete a record from the user, he/she should update the field IsActive to false. I am able to acheive this functionality using the below steps,
1. Query the database for the row which is to be updated.
2. Update the property IsActive to false.
3. Submit the changes to the database.
This way i am successful. But i have a query here is that, when we execute steps 1 and 3, there will be two trips to the database for getting the required object and again updating the same object to the database.
Is this not a performance hit having multiple calls to DB for a simple operation.?
Do we have any other go, where in within a single call to database, can i update a field of row?
i got a problem to update my database which i bounded to datagrid. The problem is, i want to update my database only by clicking one update button at the bottom.. when the user click it, all the fields will be updated to database.
have the DataTable having thousands of record ,I need to modify the rows using some c# function,I do not want to iterate through each row.So how can I use linq for it.
Could anyone provide me more info regarding this subject because I'm clueless. Any link, tutorial or anything else would be appreciated. The problem is I don't know where to start, but what I have to do is to import data from Access database to very similar SQL database.
Im trying to update my DB(DataBase) by using SQL UPDATE query ,but its not updating in the dataBase i receive confirmation(in testLabel) that one row is affected(dataReader = query.ExecuteReader(); return numbers of rows affected)...
I have given a HTML editortext control on a page,which generates HTML (i have to store it in my DB,that page is only for Admin) ,on pressing Update button , im receving in my testLabel that one row is affected(which shows DB is updated succesfully) but when i check my DB its in old state,it is not updating...
Here is my Event handler of Update Button which have to make updates in DB:
How can I update an existing LINQ entity? This code gives me: "Cannot insert an entity that already exists." Any better practises on updating/inserting with linq?
foreach (ListViewItem lvi in lvStudents.Items) { HiddenField hfStudentID = lvi.FindControl("hfID") as HiddenField; CheckBox cbPresent = lvi.FindControl("mycb") as CheckBox; int sInt = Int32.Parse(hfStudentID.Value); dc = new DataClassesSODataContext();//I renewed the dc to make sure that wasn't the problem? var currStudent = dc.students.Single(x => x.studentID == sInt); grade g = dc.grades.Single(x => x.subjectID == subjID || x.studentID == sInt); if (g == null) { g = new grade(); g.subject = dc.subjects.Single(x => x.subjectID == subjID); g.student = currStudent; g.present = cbPresent.Checked; dc.grades.InsertOnSubmit(g); } else { g.present = cbPresent.Checked; dc.grades.Attach(g, true);//I tried both attaching and inserting } } dc.SubmitChanges();
Is there a quick and easy way to update my LINQ dbml files?Right now, if I update a Stored Procedure, I need to open the dbml designer file, delete the old SP, save, drag and drop the new SP, and save again. Dont' get me wrong, this isn't "hard"... just with all the fancy new technology out there, it would be nice to be able to just right-click and hit "update".
I am having a hard time attempting to update a single field without having to retrieve the whole record prior to saving.
For example, in my web application I have an in place editor for the Name and Description fields of an object. Once you edit either field, it sends the new field (with the object's ID value) to the web server. What I want is the webserver to take that value and ID and only update the one field. There are only two ways google tells me to do this:
1) When I get the value I want to change, the value and the ID, retrieve the record from the database, update the field in the c# object, and then send it back to the server. I don't like this method because not only does it include a completely unnecessary database read call (which includes two tables due to the way my schema is).
2) Set UpdateCheck for all the fields (but the primary keys) to UpdateCheck.Never. This doesn't work for me (I think) due to my mapping layer between the Linq to Sql and my Entity/ViewModel layer. When I convert my entity into the linq to sql db object it seems to be updating those fields regardless of the UpdateCheck setting. This might be just because of integers, since not setting an int means it is a zero (and no, I can't use int? instead).
I have tables two tables, the "book" and the "author", a book can have many authors and vice versa, so there is an intermediate table called "book_author" with two columns as foreign key for those two primary keys
book_author book_id author_id
I'm trying to edit the book details and also its author using the entity date model, The controller class method
[Code]....
The HTML edit form
[Code]....
I can only update the book table, but not author that the book has or the book_author, I'm new to asp.net, I can't easily find a tutorial on this issue, I think the logic is to delete the author of the book first and then add the author for that book, but I don't know exactly about that linq and C# code. Can show me? I can only update the book table, but not author that the book has or the book_author, I'm new to asp.net, I can't easily find a tutorial on this issue, I think the logic is to delete the author of the book first and then add the author for that book, but I don't know exactly about that linq and C# code.
I have implemented a generic repository patteren for performing CRUD operations against a database. Functions Insert/Delete/GetSingle works fine but update method doesn't work whenever database table consist of relationships but for standalone table it works fine.When i try to update a table with relationship i get following error:An attempt has been made to Attach or Add an entity that is not new, perhaps having been loaded from another DataContext. This is not supported.Here is my update method:
I have a class Trans with various properties, including a boolean named Deleted.I have a generic list of Trans that are loaded from the database. I want to use linq to set all the Trans in this list to Deleted. Can I use linq to do this?
I am using Linq-To-Sql to add people to a one-to-one table. Sometimes I get a error "Violation of PRIMARY KEY constraint" when the person is already added. Can anyone give me instruction on how to handel the exception.
But the UpdateUser field does not update - it remains at NULL. No errors occur. I can use similar code to update table fields in other dbmls successfully.
i am working on Linq,as we know to use any table in linq we have to drag and drop it on our datacontext's Designer File,and at run time we got its value,till here no any problem,main point is if any changes in respective data source's schema has made ,then on datacontext we will not get that changes,for it we have to change this datacontext manually by by again drag and drop,it will not happen implicitly when this changes has been made on the data source. how i solve this problem so that datacontext change implicitly without any over head using .net 3.5.
I have a method to execute two "Update" sql statements.
The first one works fine and the second one I can't get to work for nothing.
Here is the entire method:
[Code]....
The error I am getting is "Incorrect syntax near '05'."
It is occuring on the next to the last line which is:
dc.ExecuteCommand(sql);
I update the variable "sql" first so I can debug. At the time it crashes the value of sql is:
"Update Blogs set Status = 'Archived', ArchiveDate = 06/22/2010 05:14:46 PM Where (BlogID != 1) and (Status = 'Published') and (AuthorID = 9e37e028-c205-4903-920e-e8643b30a724)"
It appears to be the ArchiveDate that is causing the problem here. The "05" is the hour of the time portion. Both ArcgiveDate and PublishDate are defined exactly the same in the database. If you look at the first dc.ExecuteCommand it does exactly the same thing with PublishDate (DateTime column) in the same table and it works just fine.
Then I modifed the code and remove the ArchiveDate from the sql statement then I get the error:
"Incorrect syntax near 'e028'."
which as you can see is part of the AuthorIDs value in the where clause. So I am assuming both the date and the Guid / Author ID is causing problems. I have tried enclosing the values in quotes but I just cant make this work even though it seems to be working fine in other places.
I even remove the code for the author ID and left in the code for the ArchiveDate and it still does not work so I have proved that both are causing a problem.