This is a continuation of my previous question: Could not find the implementation of the query template
Now I managed to query my database, I can not get the content on my web page.
I am trying to return the code using the following code:
private void button1_Click(object sender, RoutedEventArgs e) { Service1Client client = new Service1Client(); client.GetPersoonByIDCompleted += new EventHandler<GetPersoonByIDCompletedEventArgs>(client_GetPersoonByIDCompleted); client.GetPersoonByIDAsync("1"); } void client_GetPersoonByIDCompleted(object sender, GetPersoonByIDCompletedEventArgs e) { if (e.Error != null) textBox1.Text = e.Error.ToString(); else label1.Content = e.Result.Voornaam.ToString(); }
However, when I click the button, I get the following errors:
The reference to the object is not installed in the object instance.
in SilverlightApplication1.MainPage.client_GetPersoonByIDCompleted (Sender Object, GetPersoonByIDCompletedEventArgs e) on SilverlightApplication1.ServiceReference1.Service1Client.OnGetPersoonByIDCompleted (State Object)
It is strange that this works when I do not use LINQ, but plain SQL.
string sql = "SELECT ID, naam, voornaam, leeftijd FROM tblPersoon WHERE id=@pmID"; Persoon pers = null; string connstr = ConfigurationManager.ConnectionStrings["connDB"].ConnectionString; using (SqlConnection cn = new SqlConnection(connstr)) { SqlCommand com = new SqlCommand(sql, cn); com.Parameters.AddWithValue("pmID", id); cn.Open(); SqlDataReader reader = com.ExecuteReader(); if (reader.Read()) { pers = new Persoon(); pers.ID = reader.GetString(0); pers.Naam = reader.GetString(1); pers.Voornaam = reader.GetString(2); pers.Leeftijd = reader.GetInt32(3); } } return pers; }
LINQ result:

SQL result:

Thanks for helping me, I appreciate it! Thomas
sql linq silverlight wcf
Schoof Nov 21 '11 at 18:30 2011-11-21 18:30
source share