• 11-01-2013, 19:35:28
    #1
    using System;
    using System.Collections.Generic;
    using System.Data;
    using System.Data.SqlClient;
    using System.Linq;
    using System.Web;
    using System.Web.Script.Serialization;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    
    namespace Jsonyap
    {
        public partial class _Default : System.Web.UI.Page
        {
            protected void Page_Load(object sender, EventArgs e)
            {
                JavaScriptSerializer js = new JavaScriptSerializer();
                string query = String.Format("SELECT * FROM lecturer ORDER BY id;");
                try
                {
                 /*   foreach (DataRow item in SorguCalistir(query).Tables["lecturers"].Rows)
                    {
                        hoca h1 = new hoca();
                        h1.id = Convert.ToInt16(item["id"].ToString());
                        h1.Name = item["Name"].ToString();
                        h1.Rank = item["Rank"].ToString();
                        h1.Research = item["Researh"].ToString();
                        h1.Email = item["Email"].ToString();
                        h1.Office = item["Office"].ToString();
                        h1.PhoneNumber = item["PhoneNumber"].ToString();
                        string str = js.Serialize(h1);
                        Label1.Text = str;
                    }*/
    
                    SqlConnection con = new SqlConnection("Server=Gorkem;Database=hocalar;Trusted_Connection=True;");
                    con.Open();
                    SqlCommand sorgu = new SqlCommand();
                    sorgu.Connection = con;
                    sorgu.CommandText = query;
                    SqlDataReader data = sorgu.ExecuteReader();
                   
                    while (data.Read())
                    {
                        Hoca h1 = new Hoca();
                        Lecturer l1 = new Lecturer();
                        l1.id = Convert.ToInt16(data[0].ToString());
                        l1.Name = data[1].ToString();
                        l1.Rank = data[2].ToString();
                        l1.Research = data[3].ToString();
                        l1.Email = data[4].ToString();
                        l1.Office = data[5].ToString();
                        l1.PhoneNumber = data[6].ToString();
                        h1.lecturer.Add(l1);
                        string str = js.Serialize(h1);
                        Label1.Text += str;
                    }
                }
                catch (Exception ex)
                {
    
                    Label1.Text = ex.Message.ToString();
                }
               
            }
    
            public DataSet SorguCalistir(string query)
            {
    
                SqlConnection con = new SqlConnection("Server=Gorkem;Database=hocalar;Trusted_Connection=True;");
                con.Open();
                SqlDataAdapter da = new SqlDataAdapter(query, con);
                da.SelectCommand.ExecuteNonQuery();
                DataSet dt = new DataSet();
                da.Fill(dt);
                return dt;
    
    
            }
    
        }
    }
    public class Lecturer
    {
        public int id { get; set; }
        public string Name { get; set; }
        public string Rank { get; set; }
        public string Research { get; set; }
        public string Email { get; set; }
        public string Office { get; set; }
        public string PhoneNumber { get; set; }
    }
    
    
    public class Hoca
    {
        public List<Lecturer> lecturer { get; set; }
    }
    kırmızı ile belirttiğim alanda hata veriyor
  • 11-01-2013, 19:50:11
    #2
    hata mesajınıda yazar mısın
  • 11-01-2013, 19:59:00
    #3
    şöyle birşey var sorunsuz sekılde verılerı alıyor h1.lecturer.add içine atmıyor malasef try catch buldugu hata : Nesne başvurusu bir nesnenin örneğine ayarlanmadı.

    --R10.NET; Flood Engellendi -->-> Yeni yazılan mesaj 19:59:00 -->-> Daha önceki mesaj 19:53:23 --

    Açıkcası yapmaya calıstıgım sey su Jsonun bana verdıgı text :

    { 
       "id": 1, 
       "Name": "Muhammed Salamah", 
       "Rank": "(Assoc. Prof. Dr.) Chairman", 
       "Research": "Research Area: Wireless Networks, Computer Networks, Performance Evaluation and Queuing Theory, Multiprocessing, Hardware-oriented Algorithms, Positioning Systems, Parallel Processing", 
       "Email": "muhammed.salamah@emu.edu.tr", 
       "Office": "CMPE213 ", 
       "PhoneNumber": "03926301484" 
    } { 
       "id": 2, 
       "Name": "Cem Ergün", 
       "Rank": "(Asst. Prof. Dr.) Vice Chair", 
       "Research": "Research Area: Environmental Sound Recognition, Music information Retrieval, Speaker and Face Recognition, Application of Genetic Algorithms and Neural Networks to Communication", 
       "Email": "cem.ergun@emu.edu.tr", 
       "Office": "CMPE108 ", 
       "PhoneNumber": "03926301189" 
    } { 
       "id": 3, 
       "Name": "Önsen Toygar ", 
       "Rank": "(Asst. Prof. Dr.) Vice Chair", 
       "Research": "Research Area: Unimodal and Multimodal Biometric Recognition Systems (Face, Iris and Facial Expression Recognition), Human Age Classification/Estimation, Multiple Classifier Combination,", 
       "Email": "onsen.toygar@emu.edu.tr", 
       "Office": "CMPE212 ", 
       "PhoneNumber": "03926301193" 
    }
    Kodu boyle verıyor mesela ben buna en ustune hangı tablodan cıktıysa onu yazmak ıstıyorum örnek verme gerekirse
    {"lecturer": [{ 
       "id": 1, 
       "Name": "Muhammed Salamah", 
       "Rank": "(Assoc. Prof. Dr.) Chairman", 
       "Research": "Research Area: Wireless Networks, Computer Networks, Performance Evaluation and Queuing Theory, Multiprocessing, Hardware-oriented Algorithms, Positioning Systems, Parallel Processing", 
       "Email": "muhammed.salamah@emu.edu.tr", 
       "Office": "CMPE213 ", 
       "PhoneNumber": "03926301484" 
    } { 
       "id": 2, 
       "Name": "Cem Ergün", 
       "Rank": "(Asst. Prof. Dr.) Vice Chair", 
       "Research": "Research Area: Environmental Sound Recognition, Music information Retrieval, Speaker and Face Recognition, Application of Genetic Algorithms and Neural Networks to Communication", 
       "Email": "cem.ergun@emu.edu.tr", 
       "Office": "CMPE108 ", 
       "PhoneNumber": "03926301189" 
    } { 
       "id": 3, 
       "Name": "Önsen Toygar ", 
       "Rank": "(Asst. Prof. Dr.) Vice Chair", 
       "Research": "Research Area: Unimodal and Multimodal Biometric Recognition Systems (Face, Iris and Facial Expression Recognition), Human Age Classification/Estimation, Multiple Classifier Combination,", 
       "Email": "onsen.toygar@emu.edu.tr", 
       "Office": "CMPE212 ", 
       "PhoneNumber": "03926301193" 
    } 
    ]}
  • 11-01-2013, 20:19:28
    #4
    çok dikat edemedim ama hoca sınfıındaki lecturer listden bir instanance yaratman gerekir

    h1.lecturer = new Lecturer(); gibi.. bunu while dan önce yap.
    ondan sonra çalışması lazım.
    olmadıysa hata verdiği satıra breakpoint koy. hangi nesnenin null olduğuna bak
  • 11-01-2013, 20:22:26
    #5
    ertan2002 adlı üyeden alıntı: mesajı görüntüle
    çok dikat edemedim ama hoca sınfıındaki lecturer listden bir instanance yaratman gerekir

    h1.lecturer = new Lecturer(); gibi.. bunu while dan önce yap.
    ondan sonra çalışması lazım.
    olmadıysa hata verdiği satıra breakpoint koy. hangi nesnenin null olduğuna bak
    kodu yazdıgımda
      Hoca h1 = new Hoca();
                    Lecturer l1 = new Lecturer();
                    h1.lecturer = new Lecturer();
                    while (data.Read())
                    {
                        
                        l1.id = Convert.ToInt16(data[0].ToString());
                        l1.Name = data[1].ToString();
                        l1.Rank = data[2].ToString();
                        l1.Research = data[3].ToString();
                        l1.Email = data[4].ToString();
                        l1.Office = data[5].ToString();
                        l1.PhoneNumber = data[6].ToString();
                        h1.lecturer.Add(l1);
                        string str = js.Serialize(h1);
                        Label1.Text += str;
                    }
    Error 1 Cannot implicitly convert type 'Lecturer' to 'System.Collections.Generic.List<Lecturer>' C:\Users\gkaradagan\Desktop\Microsoft Visual Studio WorkSpace\Jsonyap\Jsonyap\Default.aspx.cs 44 31 Jsonyap

    Boyle bir hata cıkıyor ...
  • 11-01-2013, 20:49:24
    #6
    pardon hoca çok dikkat edemedim dedim
    List<Lecturer> (); dene sadece lecturer yerine

    h1.lecturer = new List<Lecturer> ();
  • 11-01-2013, 21:15:47
    #7
    ertan2002 adlı üyeden alıntı: mesajı görüntüle
    pardon hoca çok dikkat edemedim dedim
    List<Lecturer> (); dene sadece lecturer yerine

    h1.lecturer = new List<Lecturer> ();
    oldu valla =) ellerine yüreğine sağlık sabahtan berı ugrasıyorum dıger arkadaslarada teşekkuırler...

    --R10.NET; Flood Engellendi -->-> Yeni yazılan mesaj 21:15:47 -->-> Daha önceki mesaj 20:51:56 --

    {
        "lecturer": [{
            "id": 1,
            "Name": "Muhammed Salamah",
            "Rank": "(Assoc. Prof. Dr.) Chairman",
            "Research": "Research Area: Wireless Networks, Computer Networks, Performance Evaluation and Queuing Theory, Multiprocessing, Hardware-oriented Algorithms, Positioning Systems, Parallel Processing",
            "Email": "muhammed.salamah@emu.edu.tr",
            "Office": "CMPE213 ",
            "PhoneNumber": "03926301484"
        }]
    } {
        "lecturer": [{
            "id": 2,
            "Name": "Cem Ergün",
            "Rank": "(Asst. Prof. Dr.) Vice Chair",
            "Research": "Research Area: Environmental Sound Recognition, Music information Retrieval, Speaker and Face Recognition, Application of Genetic Algorithms and Neural Networks to Communication",
            "Email": "cem.ergun@emu.edu.tr",
            "Office": "CMPE108 ",
            "PhoneNumber": "03926301189"
        }]
    } {
        "lecturer": [{
            "id": 3,
            "Name": "Önsen Toygar ",
            "Rank": "(Asst. Prof. Dr.) Vice Chair",
            "Research": "Research Area: Unimodal and Multimodal Biometric Recognition Systems (Face, Iris and Facial Expression Recognition), Human Age Classification/Estimation, Multiple Classifier Combination,",
            "Email": "onsen.toygar@emu.edu.tr",
            "Office": "CMPE212 ",
            "PhoneNumber": "03926301193"
        }]
    }
    bu seferde kodu boyle verıyor ayrı ayrı bunların hepsı bir lecturer'ın ıcınde olması gerekiyor ?
  • 11-01-2013, 23:09:39
    #8
    çözmüşsün sanırım sorununu?