I am trying to add personnel information to an automation with Entity, but when trying to add email information , Validating error evolves. What should i do?
error:
An unhandled exception of type 'System.Data.Entity.Validation.DbEntityValidationException' occurred in EntityFramework.dll
Additional information: Validation failed for one or more entities. See 'EntityValidationErrors' property for more details.
and my code:
CateringDBEntities sws = new CateringDBEntities();
private void button1_Click(object sender, EventArgs e)
{
Personel sws2 = new Personel();
sws2.p_name = textBox1.Text;
sws2.p_sname = textBox2.Text;
sws2.p_mail = textBox3.Text;
sws.Personel.Add(sws2);
sws.SaveChanges();
MessageBox.Show("Öğrenci Eklendi.");
this.Close();
}
Related
I am new to WPF. I am unable to write how the code ms access Entity Framework delete code
private void Window_Loaded(object sender, RoutedEventArgs e)
{
AMXCOMPANYDETAILS.AMX_SalesDBDataSet aMX_SalesDBDataSet = ((AMXCOMPANYDETAILS.AMX_SalesDBDataSet)(this.FindResource("aMX_SalesDBDataSet")));
// Load data into the table tblContact. You can modify this code as needed.
AMXCOMPANYDETAILS.AMX_SalesDBDataSetTableAdapters.tblContactTableAdapter aMX_SalesDBDataSettblContactTableAdapter = new AMXCOMPANYDETAILS.AMX_SalesDBDataSetTableAdapters.tblContactTableAdapter();
aMX_SalesDBDataSettblContactTableAdapter.Fill(aMX_SalesDBDataSet.tblContact);
System.Windows.Data.CollectionViewSource tblContactViewSource = ((System.Windows.Data.CollectionViewSource)(this.FindResource("tblContactViewSource")));
tblContactViewSource.View.MoveCurrentToFirst();
// Load data into the table tblContactAddress. You can modify this code as needed.
AMXCOMPANYDETAILS.AMX_SalesDBDataSetTableAdapters.tblContactAddressTableAdapter aMX_SalesDBDataSettblContactAddressTableAdapter = new AMXCOMPANYDETAILS.AMX_SalesDBDataSetTableAdapters.tblContactAddressTableAdapter();
AMX_SalesDBDataSettblContactAddressTableAdapter.Fill(aMX_SalesDBDataSet.tblContactAddress);
System.Windows.Data.CollectionViewSource tblContactAddressViewSource = ((System.Windows.Data.CollectionViewSource)(this.FindResource("tblContactAddressViewSource")));
tblContactAddressViewSource.View.MoveCurrentToFirst();
}
I am trying to get a simple WebClient call working from Silverlight to youtube. I lifted the code from the Microsoft Silverlight site.
Here is the code:
private void SearchTrack_Click(object sender, RoutedEventArgs e)
{
Uri serviceUri = new Uri("https://www.googleapis.com/youtube/v3/search?part=id%2Csnippet&q=sara+smile&key=AAAAAAAAAAAAAAA");
WebClient downloader = new WebClient();
downloader.OpenReadCompleted += new OpenReadCompletedEventHandler(downloader_OpenReadCompleted);
downloader.OpenReadAsync(serviceUri);
}
void downloader_OpenReadCompleted(object sender, OpenReadCompletedEventArgs e)
{
if (e.Error == null)
{
Stream responseStream = e.Result;
// Continue working with responseStream here...
}
}
The call fails with the following error:
[System.Security.SecurityException] = {System.Security.SecurityException ---> System.Security.SecurityException: Security error.
at System.Net.Browser.BrowserHttpWebRequest.InternalEndGetResponse(IAsyncResult asyncResult)
at System.Net.Browser.BrowserHttpWebRequest.<>c__DisplayClassa.
If I just hit the URL from my browser the JSON is returned without an issue.
I am running the application from VS/Cassini so I don't think it is the FIle system problem identified at http://blogs.msdn.com/b/silverlightws/archive/2008/03/30/some-tips-on-cross-domain-calls.aspx.
Any help would be greatly appreciated.
Barry
Here it's said, that it's not possible so easy to interract with google apis from silverlight because of corssdomain access restrictions. You need to add some intermidiate WCF-service, through which Your SL-app will communicate with youtube api.
And how can I present it to the user?
This post : WCF Duplex: How to handle thrown exception in duplex Callback is very close to my scenario. And this post is useful for helping me re-establish the connection when the channel is faulted.
I have a Publishing application Pub, and a subscribing WPF application Sub. The Pub sends a message and the Sub has subscribed for a callback using a duplex channel.
Sub.ViewModel.ReactToChange(sender, e) tries to read some data, but is unable to and throws an exception.
DispatcherUnhandledException doesn't catch it (I didn't really expect it to.)
AppDomain.CurrentDomain.UnhandledException doesn't catch it (that does surprise me)
The end result is I have an application that is still running, and no exception message is shown to the user so they can correct the problem. Is there a way I can show that exception to the user?
This is a bit tricky, but the only way I've found. I hope this helps others.
The idea is to not let an exception get thrown, but instead create an UnhendledExceptionEventArg and pass it up to your UI layer. Here is some example code:
public class BuggySubscriber : IDisposable
{
public BuggySubscriber(string dataSourceName)
{
SyncContext = SynchronizationContext.Current;
Subscriber = new MockSubscriber(dataSourceName);
Subscriber.Refreshed += OnDataChanged;
}
public SynchronizationContext SyncContext { get; set; }
public event EventHandler<UnhandledExceptionEventArgs> ExceptionOccurred;
// Bouncing Exception Step 3
private void OnExceptionOccured(Exception ex)
{
var callback = new SendOrPostCallback(delegate
{
var handler = ExceptionOccurred;
if (!ReferenceEquals(handler, null))
handler(this, new UnhandledExceptionEventArgs(ex, true));
});
SyncContext.Post(callback, null);
}
void OnDataChanged(object sender, ServiceModel.DataChanged.DataChangedEventArgs e)
{
// Bouncing Exception Step 1 & 2
OnExceptionOccured(new NotImplementedException());
}
So this is the "Sub" code. In the WPF application I add the following when the app starts:
protected override void OnStartup(StartupEventArgs e)
{
AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
BuggySubscriber.ExceptionOccurred += Sub_ExceptionOccurred;
...
}
// Bouncing Exception Step 5
void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
{
var exception = e.ExceptionObject as Exception;
if (!ReferenceEquals(exception, null))
ShowErrorMessage(exception);
}
// Bouncing Exception Step 4
void Sub_ExceptionOccurred(object sender, UnhandledExceptionEventArgs e)
{
var exception = e.ExceptionObject as Exception;
if (!ReferenceEquals(exception, null))
throw exception;
}
So now let's try to follow the bouncing exception.
In real life, the subscriber was notified and an exception occurs and is caught. (In my sample, I don't show that.)
Then the OnExceptionOccurred(Exception ex) is called.
That then creates the SendOrPostCallback using the ExceptionOccurred event and then does a Post to the current SynchronizationContext.
The WPF application that registered for the ExceptionOccurred (Now if you like, you could handle the exception message here... I chose to use two paths for exceptions rather than three.) It casts and throws the Exception.
Now the CurrentDomain_UnhandledException processes it and shows an error message to the user (right before it exits).
I'm sure there are many variations on this, but this does show some of the trickier code that I could not find in one place.
NOTE: This does not solve any channel problems. If you have an exception you can recover from you will still need to reestablish the channel since it will be faulted or closed.
I have been trying to follow this blog http://world.episerver.com/Blogs/Anders-Hattestad/Dates/2013/1/Upload-within-Xform/
The form upload works, however the file does not appear in the email, but is uploaded onto the server, so its doing something.
The instructions I have are...
Just attach to the
BeforeSubmitPostedData event
Check if ((e.FormData.ChannelOptions & ChannelOptions.Email) != ChannelOptions.Email) is true
then send the custom mail and remove the send mail option
e.FormData.ChannelOptions &= ~ChannelOptions.Email;
If anyone could simplify this for me, would be appreciated...
Many Thanks.
Marc.
in Application_Start in your global.asax you need to attach to the XFormControl.ControlSetup Event
protected void Application_Start(object sender, EventArgs e)
{
XFormControl.ControlSetup += new EventHandler(XForm_ControlSetup);
}
Then in your XForm_ControlSetup method, attach to the relevant event
public void XForm_ControlSetup(object sender, EventArgs e)
{
XFormControl control = (XFormControl)sender;
control.BeforeSubmitPostedData += new SaveFormDataEventHandler(XForm_BeforeSubmitPostedData);
}
And in your XForm_BeforeSubmitPostedData method
public void XForm_BeforeSubmitPostedData(object sender, SaveFormDataEventArgs e)
{
// Untested
if ((e.FormData.ChannelOptions & ChannelOptions.Email) != ChannelOptions.Email)
{
// Send custom mail here
// Remove the send mail option
e.FormData.ChannelOptions &= ~ChannelOptions.Email;
}
// End untested :)
}
I'm running into an interesting situation. I need to access a SharePoint site asset library from both a WPF application and an Silverlight application. My Silverlight application is working 100%, but my WPF application gets a (500) Internal Server Error back from the service.
Silverlight Code:
private void Button_Click(object sender, RoutedEventArgs e)
{
ClientContext clientContext = new ClientContext("http://myfullyQualifiedName.com");
clientContext.Load(clientContext.Web);
clientContext.ExecuteQueryAsync(onQuerySucceeded, onQueryFailed);
}
private void onQuerySucceeded(object sender, ClientRequestSucceededEventArgs args)
{
}
private void onQueryFailed(object sender, ClientRequestFailedEventArgs args)
{
}
WPF Code:
private void Button_Click(object sender, RoutedEventArgs e)
{
ClientContext clientContext = new ClientContext("http://myfullyqualifiedname.com/");
//clientContext.Credentials = new NetworkCredential("UserName", "Password", "Domain");
clientContext.Load(clientContext.Web);
clientContext.ExecuteQuery();
}
I have tried with and without specifying credentials, either way I get the Internal server error.
Both Silverlight and non Silverlight Sharepoint client DLL's that I use has is version 14.4762.1000.
Now if I change the URL to one of our other sites, the WPF Code works flawlessly. So I think it must be a SharePoint settings somewhere.
Solved !! Why WPF Authentication wouldn't work when Silverlight works. (WPF was trying to use Kerberos, Silverlight was using NTLM) - Simple fix:
ClientContext _clientContext = new ClientContext(sharePointSiteUrl);
Web _web = _clientContext.Web;
_clientContext.Load(_web, website => website.Title);
_clientContext.Load(_web.Webs);
CredentialCache cc = new CredentialCache();
cc.Add(new Uri(sharePointSiteUrl), "NTLM", CredentialCache.DefaultNetworkCredentials);
_clientContext.Credentials = cc;
_clientContext.AuthenticationMode = ClientAuthenticationMode.Default;
_clientContext.ExecuteQuery();
ListCollection _listCollection = _web.Lists;