In A Datacontext Are Inserted Values Not Available Within Datacontext Until After Submitchanges

Mar 18, 2009

I'm going through an XML file of articles and the journalist(s) that wrote them. As we are adding the articles into _Data our datacontext we may come across a journalist that needs adding so we do this: [code] However subsequently we may come across this same journalist again and nothing is returned when we do this: [code] So it uses the code above again to insert the same journalist again.Once all of our inserts are done we do a submitchanges. At this point it has a head fit:INSERT statement conflicted with COLUMN FOREIGN KEY constraint 'FK_ articles_ journalists_journalists'. The conflict occurred in database 'blah', table 'journalists', column 'id'. The statement has been terminated.From looking through the sql generated in sql profiler you can see that it is trying to add some journalists more than once, this will fail as the name must be distinct. The subsequent records that are trying to be inserted with these journalists are failing as the journalist wasn't updated.Surely if I have a collection of journalists, add some to it and then look in my collection I should see all of them and not just the original ones.

View 3 Replies


ADVERTISEMENT

Get Data From MenuItem.DataContext?

Dec 15, 2011

I have a context menu on my DataTemplete for a list box, and that menu will contain links to Favourite and Retweet the tweet (the menu item) But I don't know how to get the information about the Tweet in code. I am trying the following Line:

[Code]...

View 3 Replies

LINQ To SQL DataContext To XML With XSD Schema?

Dec 27, 2010

I have some data in my Linq.DataContext.I had succes in converting it to an XSD - Schema, using the following code:

Dim changeset As System.Data.Linq.ChangeSet = c.GetChangeSet()
Dim objDic As New Dictionary(Of System.Type, List(Of Object))
If Not changeset Is Nothing AndAlso Not changeset.Inserts Is Nothing AndAlso Not

[code].....

View 1 Replies

Overriding Datacontext For View?

Mar 15, 2012

I am setting my viewmodel as datacontext in my xaml but I override it to my view to make few functions work however to achieve the visibility on some grids and I have a property in my VM can I override my datacontext back to my VM? If so how? I have a stackpanel that has datacontext overriden as my grid and within that stackpanel I need to change the datacontext for a button.

View 1 Replies

DataContext - Discard Changes Of Only One Record In Table

Apr 1, 2010

I would like to know if its possible to discard changes of only one record of only one table in datacontext. I use databind to bind my controls on a form. I modify one record at a time. after the modification, the user have to hit save button to validate. But he can hit cancel. I would like that the cancel button discard all the changes that the user has done. Is it possible?

View 3 Replies

Difference Between Using DataContext Class And SqlConnection?

Mar 2, 2012

I asked a question earlier where I was told a simple way to "bind data to objects" is to just run a SqlConnection(connectionString). The response also included a comment saying I could get fancy with L2S and Entity Frameworks, so I looked deeper into those. It seems all you have to do with the DataContext object is point to the database. Why would SqlConnection be a benefit? What is the difference (or pros/cons) of using either one of these? Is one more "standard"? Is one more modern?

View 1 Replies

Two Way Binding LINQ To SQL DataContext Classes

Aug 17, 2009

How to bind a textbox in design view to a LINQ to SQL datacontext class?

View 3 Replies

Understanding ItemsSource And DataContext In A DataGrid?

Jun 14, 2010

UPDATE: See the bottom of this question for what I did to solve the problem.I'm trying to understand how the ItemsSource and DataContext properties work in a Silverlight Toolkit DataGrid. I'm currently working with dummy data and trying to get the data in the DataGrid to update when the value of a combo box changes.

View 2 Replies

Check Whether A Linq-to-SQL Object Is Already Attached To A DataContext?

Jun 27, 2011

I have an object that may have been inflated via a plain old DataContext, or may just have been new-ed up with just its .ID property set. There's no way to know for sure. I'm looking to rehydrate the entire object from whatever is in the database. If the object was new-ed up, I can call .Attach() on the table object and refresh from the Data Context with no trouble. But, if the object was already inflated from the DataContext I get the error: "Cannot attach an entity that already exists.". There's no timestamp field or anything like that - just an integer primary key being used to control the rehydration. I'd like to know if there's a way to conditionally attach. Here's the code - it works the way I want it to, but this seems a hackish way to go about it:

' myDC is a shared instance of a vanilla DataContext...
' myObj is an instance of a linqed-up `SomeLinqObject`
Dim tbl = myDC.GetTable(Of SomeLinqObject)()

[Code[,,,,,

View 1 Replies

Setting The DataContext On An Entity Instance After It's Retrieved?

Apr 14, 2011

I'm trying to find a way to have the DataContext available from within Entities.

I want to do something like this:

partial public class MyEntity
public DataContext as MyDataContext
private sub OnLoaded()

[Code]....

View 2 Replies

Setting User Control's DataContext From Code-Behind?

Jul 8, 2009

This should be pretty easy, but it throws VS2008 for a serious loop.I'm trying out WPF with MVVM, and am a total newbie at it although I've been developing for about 15 years, and have a comp. sci. degree. At the current client, I am required to use VB.Net. I have renamed my own variables and removed some distractions in the code below, so please forgive me if it's not 100% syntactically perfect! You probably don't really need the code to understand the question, but I'm including it in cas.

I have a very simple MainView.xaml file:
<Window x:Class="MyApp.Views.MainView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

[code].....

View 3 Replies

Using Same Connection String In A DataContext Constructor And SqlConnection?

Oct 4, 2011

I am preparing to deploy a web service that uses SqlConnection primarily as its means to get to the database, and I am adding some new methods that use a DataContext instead of thatand the default constructor and DBML file would use a connection string refering to my development machine (I believe...)

View 1 Replies

Wpf - DataContext Issues With ListBox After Changes To MainWindow.xaml?

Jun 18, 2012

I am new to WPF and the MVVM design pattern this month, and more than a little out of practice in general. To learn, I've been playing around with textboxes, rectangles, and ways to display them in a window. I began with Ashley Davis' excellent "Simple Drag Selection in WPF" tutorial, which walks through creating a view model for a collection of rectangles, binding a listbox to said collection, and styling the listbox with a canvas, creating a data template for the rectangles, as well as basic "rubber band" selection logic.

I have since built on this tutorial to improve the drag selection so that it behaves much more like selection does in windows explorer, and to allow resizing the rectangles from the corners or edges.All was well until I changed the MainWindow.xaml in an effort to include a column on the side for various buttons and controls, thus moving the "editor surface" grid from inside a 1x1 grid on the main window to a column of a 1x2 grid, moving the data template to the grid's resources (since it will be the only element in the window that needs it). As soon as I did this, subroutines that I wrote which interact with the listbox started misbehaving--rubber band selection no longer works. There's no visual indication that listbox items are being selected (they were highlighted previously), and interrogating listBox.SelectedItems.Count after a drag-selection mouseUp event returns a zero.

After some experimentation, reading many questions on this site and sections of my WPF Unleashed book, and going over the msdn databinding overview, as of this morning I still cannot find my mistake(s). I believe it is a data binding mistake or incorrect data context.Some details about the view models involved:

DataFieldViewModel

...implements INotifyPropertyChanged and exposes properties for its (in this case a rectangle and a textbox) X,Y position, width, height, visibility, and selection status (a way to track it across several rubber band selection operations)

PageViewModel

...implements INotifyPropertyChanged, and has among other things an ObservableCollection of type DataFieldViewModel, called DataFields, and exposes it as a ReadOnly Property.Here's a look at MainWindow.xaml.vb and one of the broken subs:

Namespace EditorUI
'
' The main window of the editor.

[code]....

View 1 Replies

DataBinding LINQ DataContext - Add A New Record Since The Textbox's Are Binded To An ISingleResult?

Aug 13, 2009

I have a LINQ to SQL DataContext with all my tables and all my stored procedures in it. Let me first start off by saying that we are upgrading our project from an access project to a WPF project. So in the Access project you could set a forms datasource to a stored procedure and edit and add new information. So in my WPF project on the page load I call my stored procedure to return an ISingleResult and then call a function to set the binding on every single textbox on the form. One is there an easier way to do this and two what if I want to add a new record since the textbox's are binded to an ISingleResult?

View 2 Replies

.net - Silverlight Datacontext, Repeats All The Past Commands/action Each Time A New Action Is Performed On It

Mar 28, 2011

a datacontext defined in a module(domain services ado.net ria)a page having add/delete methods whenever any method is executed, it is found that all the previous actions (NEW RECORD ADDITION and DELETION OF RECORDS) are carried out before the new action is carried out normally

this behaviour is not prominent but "when using break points and inspecting the values of the variables and table object to be added to context, it is clear that all the previous actions take place again. even when the datacotext. savechanges is called, even after that still all actions carried out on the datacontext repeat themseleves, when any new action is to be carried out

View 1 Replies

.net - Make Sure The View Is Rendered Only When The Type Of DataContext Matches Data Template's Target Type?

Dec 10, 2010

<ItemsControl DockPanel.Dock="Top" ItemsSource="{Binding Path={x:Static vmc:clsPersonViewModel.ChildrenPath}, Mode=OneWay}">
<ItemsControl.ItemTemplate>

[Code].....

In the code above, if there are no children (the ChildrenPath property returns NULL), nothing is rendered in the view. In the code below, when ChildrenDataSetPath is NULL the XamDataGrid still gets rendered. How do I achieve the same for a single object (as opposed to a collection) as the datacontext?

<DataTemplate DataType="{x:Type vmb:clsPersonViewModel}">
<igDP:XamDataGrid DataSource="{Binding Path={x:Static vmb:clsPersonViewModel.ChildrenDataSetPath}}">

[Code].....

View 2 Replies

Prevent Duplicated Values To Be Inserted Again?

Jan 26, 2011

I have a XML file used for importing data into the database. But it does not check for duplicated values. Is there a way to prevent duplicated values to be inserted again?What is the procedures to do in corporate environment?

View 2 Replies

[2008] Wrong Values Inserted Into Database?

Mar 10, 2009

nserting values from a datagridview into an access db. However the values are wrong. As you can see in the code, I've made variables to check what values are fetched from the datagridview, and those values are correct. But in the db there are other values. What's going on?The thing is some of the fields are run-time-created comboboxes and there are also datagridviewcheckboxes. But like I said, the values in the t1...t7 variables are correct.

Private Sub DataGridView2_RowLeave(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView2.RowLeave
Dim Monda2 As New OleDb.OleDbDataAdapter("select * from congregation", Moncon)

[code].....

View 3 Replies

Datagrid To Be Inserted With Additional Values With The Prior Populated Data?

Nov 11, 2010

i have a Checkedlistbox in a windows form, and have defined 5 values in it.Also the form holds a datagrid in it. i have manually defined 2 columns in it.Now i would like to populate datagrid with some data according to the check list values selection. When any selection was done in the checkedlistbox, some data need to added to the gird.in case if i am ticking further selection, i need the datagrid to be inserted with additional values with the prior populated data.

being a beginner, i am not able to get any idea to get this worked.

View 4 Replies

Sql Server - How To Get Last Inserted Identity In Formview Inserted Event Using .net

Sep 21, 2009

I am using VB.net (FormView and ObjectDataSource) and Sql Server 2005.

I want to get last inserted @@identity in table on FormView1_ItemInserted

Protected Sub FormView1_ItemInserted(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.FormViewInsertedEventArgs) Handles FormView1.ItemInserted

End Sub My issue is that I want to redirect my FormView to readonly mode after FormView1_ItemInserted but for that I need to show the inserted record in readonly mode and that is only possible if I get my last inserted @@identity.

View 1 Replies

Linq Submitchanges Runs Out Of Memory?

Nov 25, 2010

I have a database with about 180,000 records. I'm trying to attach a pdf file to each of those records. Each pdf is about 250 kb in size. However, after about a minute my program starts taking about about a GB of memory and I have to stop it. I tried doing it so the reference to each linq object is removed once it's updated but that doeow can I make it clear the reference?

Private Sub uploadPDFs(ByVal args() As String)
Dim indexFiles = (From indexFile In dataContext.IndexFiles
Where indexFile.PDFContent = Nothing

[code]....

View 3 Replies

Retrieve Inserted Checkbox Values In Checkbox On Asp.net Page Load?

Dec 30, 2010

i have 5 checkboxes in webform and textbox1... when i search the record using the date specified in textbox1 when i enter 11-Dec-2010 in Textbox1 and click on submit button then checkbox1, checkbox2, and checkbox3 will be disabled and unchecked .....

[Code]...

View 1 Replies

.net - SubmitChanges With LINQ To SQL And User Defined Functions?

Mar 7, 2012

On the SQL server I create a UDF. Let's name it fnCompanyDetails. It selects some information about a company from several joint tables.I then drag-and-drop this function in the new .dbml of my VB project. I want to use it with LINQ. Smth like this:

[Code]...

View 1 Replies

Asp.net - InsertOnSubmit Not Triggering A Database Insert On SubmitChanges?

Aug 17, 2009

I've got a piece of code that inserts a row into a table - the kind of thing I've done in dozens of other apps - but the end result is nothing happens on the database end, and no errors are generated.

Here's my code:

Partial Class MyDatabaseDataContext
Public Sub CreateEnrollee(subId, depId)
dim newEnrollee = New enrolee With {.subId = subId, .depId = depId}

[Code]....

After SubmitChanges is called, no new row is created, and "test" is zero. No errors are generated. I have no idea why it's not trying to insert the row.

View 2 Replies

C# - Does LINQ To SQL Auto-update The LOCAL/CLIENT Id Column After A SubmitChanges Call?

Jan 18, 2010

just want to know if linq to sql auto updated the id column of a class (table row object) after SubmitChanges is called inserting a new row to that table, that would be fantastic, would anyone be able to confirm this?

View 2 Replies

.net Sql Last Inserted ID?

Dec 13, 2010

i'm using VB.NET with an Access Database, I insert values but then I need to get the last inserted ID (auto number) and insert that into a related table.I have tried @@IDENTITY and MAX(column) but @@IDENTITY returns zero and MAX isn't very dependable (sometimes slow to insert data, so get the ID before the inserted one).

Dim insertSql = datalayer.getDataTable((String.Format("INSERT INTO users (username) VALUES ({0})", username)))Dim newID = datalayer.getDataTable((String.Format("SELECT @@IDENTITY FROM users")))

[Code]...

This is done in two functions so the above code might look confusing, but thats just taken from the two functions. The two statements are executed, but I have just shown one being executed as an example.Is there and alternative to @@IDENTITY and MAX, as I carn't seem to see how am going wrong with @@IDENTITY?

View 1 Replies

Asp.net - 'Title' Is Not Getting Inserted

Sep 28, 2011

I recently changed my site to allow a user to choose from a dropdown list or a textbox to be able to insert a title. The table is called Picklist, the columns are PicklistID, Title, Data.

Protected Sub SubmitLink_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles SubmitLink.Click
LinkModal.Hide()

[Code].....

In the image below: See how in the background the line at the very top has nothing in it, but the delete button is there? That is a link that I just tried to add......the @Data column is inserted into the database, but not the @Title. But there are no errors! :/

View 1 Replies

Asp.net - Checking If Row Was Inserted?

Apr 19, 2011

I am trying to check whether a row is getting inserted into my database. It is throwing an error even when it does insert (it's a database issue that will get resolved later when I get a newer version of Microsoft Access), so I can't check whether the insert is successful based on whether there's an error or not. I think I need to check the AffectedRows of something, but I'm not sure what. I've been looking for info on how to do this but I can't figure out how to make it work for my exact situation. Here's a general idea of what my code looks like:

Protected Sub Wizard1_FinishButtonClick(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.WizardNavigationEventArgs) Handles Wizard1.FinishButtonClick

[Code]...

But the numInserted is coming out as 0 every time even though the insert is successful. It may have to do with the fact that myIns1.ExecuteNonQuery() throws an error even though the insert is successful.

-EDIT- I discovered that the "duplicate values" error is because it is somehow attempting to insert the record twice. I have no idea why it's doing that though.

View 2 Replies

Can't Select Last Inserted Row In DGV

Apr 13, 2009

i have a main form with dgv and new record form ,after inserting the record from the new record form i want the new inserted row to be selecetd in main form.

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Try

[Code]....

View 4 Replies

Extract Id Of Last Inserted Row?

Feb 28, 2012

i am inserting a row in an acces table but I also want to get the id of the last inserted row so that I can use that value. how I can go about it?

Dim iSql As String = "Insert into CompanyDetails (code,description)
Connections.MyDataAdapter(iSql)
Public Shared Function MyDataAdapter(ByVal iSql As String) As

[Code]....

View 5 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved