Asp.net c# xml RSS to sql insert.

An error occurred while parsing EntityName. Line 36, position 58.

Help

XmlDocument ReadInDocument = new XmlDocument(); 

ReadInDocument.XmlResolver = null; 

ReadInDocument.Load("XML ADRES"); 

foreach(XmlNode node in ReadInDocument.SelectNodes(".//rss/channel/item")) 
{ 

İNSERT SQL CODE

}
Member Avatar for iamthwee

No line 36 in example code shown.

`string strQuery = "insert into gelenhaberler(HaberKodu,Sehir,title,description,pubDate,link) values(@HaberKodu,@Sehir,@title,@description,@pubDate,@link)";

    SqlConnection con = new SqlConnection(strConnString); 
    con.Open();


    XmlDocument ReadInDocument = new XmlDocument();
    ReadInDocument.XmlResolver = null;
    ReadInDocument.Load("http://abone.iha.com.tr/yeniabone/RSS2.aspx?Kategori=3"); 



    foreach(XmlNode node in  ReadInDocument.SelectNodes(".//rss/channel/item"))
    { 
    SqlCommand komut1 = new SqlCommand("Select*from gelenhaberler where HaberKodu=@HaberKodu", con);
    komut1.Parameters.AddWithValue("@HaberKodu", node.SelectSingleNode("HaberKodu").InnerText);
    SqlDataReader oku = komut1.ExecuteReader();
    if (oku.HasRows)
    {

    }
    else
    {
    SqlCommand cmd = new SqlCommand(strQuery);
    cmd.CommandType = CommandType.Text;
    cmd.Connection = con;
    cmd.Parameters.AddWithValue("@HaberKodu", node.SelectSingleNode("HaberKodu").InnerText);
    cmd.Parameters.AddWithValue("@Sehir", node.SelectSingleNode("Sehir").InnerText);
    cmd.Parameters.AddWithValue("@title", Capitalize(node.SelectSingleNode("title").InnerText));
    cmd.Parameters.AddWithValue("@description",  node.SelectSingleNode("description").InnerText);
    cmd.Parameters.AddWithValue("@pubDate", Convert.ToDateTime(node.SelectSingleNode("pubDate").InnerText));
    cmd.Parameters.AddWithValue("@link", node.SelectSingleNode("link").InnerText);
    cmd.ExecuteNonQuery();
    cmd.Dispose();
    }
    komut1.Dispose();
    oku.Close();
    }  
    con.Close();
    con.Dispose(); 

    string strQuery1 = "insert into gelenhaberlerimage(HaberKodu,BuyukResim,ResimKodu) values(@HaberKodu,@BuyukResim,@ResimKodu)";
    String strConnString1 = System.Configuration.ConfigurationManager.ConnectionStrings["konsporConnectionString"].ConnectionString;
    SqlConnection con1 = new SqlConnection(strConnString1);
    con1.Open();
    XmlDocument ReadInDocument1 = new XmlDocument();
    ReadInDocument1.XmlResolver = null;
    ReadInDocument1.Load("http://abone.iha.com.tr/yeniabone/RSS2.aspx?Kategori=3"); 
    String HaberKodu = "";
    String BuyukResim = "";
    String ResimKodu = "";



    foreach (XmlNode node1 in ReadInDocument1.SelectNodes(".//images/image"))
    {
    SqlCommand komut1 = new SqlCommand("Select*from gelenhaberlerimage where ResimKodu=@ResimKodu", con1);
    komut1.Parameters.AddWithValue("@ResimKodu", node1.Attributes["ResimKodu"].InnerText);
    SqlDataReader oku = komut1.ExecuteReader();
    if (oku.HasRows)
    {

    }
    else
    {
        HaberKodu = node1.Attributes["HaberKodu"].InnerText;
        ResimKodu = node1.Attributes["ResimKodu"].InnerText;
        BuyukResim = node1.ChildNodes[0].InnerText; ;
        SqlCommand cmd1 = new SqlCommand(strQuery1);
        cmd1.CommandType = CommandType.Text;
        cmd1.Connection = con1;
        cmd1.Parameters.AddWithValue("@HaberKodu", HaberKodu.ToString());
        cmd1.Parameters.AddWithValue("@ResimKodu", ResimKodu.ToString());
        cmd1.Parameters.AddWithValue("@BuyukResim", BuyukResim.ToString());
        cmd1.ExecuteNonQuery();

    }
    oku.Close();
    }

        con1.Close();
        con1.Dispose(); 



        string strQuery2 = "insert into gelenhabersmallimage(HaberKodu,small_images,ResimKodu) values(@HaberKodu,@small_images,@ResimKodu)";
        String strConnString2 = System.Configuration.ConfigurationManager.ConnectionStrings["konsporConnectionString"].ConnectionString;
        SqlConnection con2 = new SqlConnection(strConnString2);
        con2.Open();
        XmlDocument ReadInDocument2 = new XmlDocument();
        ReadInDocument2.XmlResolver = null;
        ReadInDocument2.Load("http://abone.iha.com.tr/yeniabone/RSS2.aspx?Kategori=3"); 



        String HaberKodu1 = "";
        String small_images = "";
        String ResimKodu1 = "";

        UnescapeXMLValue(".//small_images/small_image"); 

        foreach (XmlNode node2 in ReadInDocument2.SelectNodes(".//small_images/small_image"))
        {
            SqlCommand komut1 = new SqlCommand("Select*from gelenhabersmallimage where ResimKodu=@ResimKodu", con2);
            komut1.Parameters.AddWithValue("@ResimKodu", node2.Attributes["ResimKodu"].InnerText);
    SqlDataReader oku = komut1.ExecuteReader();
    if (oku.HasRows)
    {

    }
    else
    {

        HaberKodu1 = node2.Attributes["HaberKodu"].InnerText;
        ResimKodu1 = node2.Attributes["ResimKodu"].InnerText;
        small_images = node2.ChildNodes[0].InnerText;
        SqlCommand cmd2 = new SqlCommand(strQuery2);
        cmd2.CommandType = CommandType.Text;
        cmd2.Connection = con2;
        cmd2.Parameters.AddWithValue("@HaberKodu", HaberKodu1.ToString());
        cmd2.Parameters.AddWithValue("@small_images", small_images.ToString());
        cmd2.Parameters.AddWithValue("@ResimKodu", ResimKodu1.ToString());
        cmd2.ExecuteNonQuery();
    }
    oku.Dispose();
        } 
        con2.Close();
        con2.Dispose();


        string strQuery5 = "insert into gelenhaberaciklama(HaberKodu,Aciklama) values (@HaberKodu5,@Aciklama5)";

        SqlConnection con5 = new SqlConnection(strConnString5);
        con5.Open();
        XmlDocument ReadInDocument5 = new XmlDocument();
        ReadInDocument5.XmlResolver = null;
        ReadInDocument5.Load("http://abone.iha.com.tr/yeniabone/RSS2.aspx?Kategori=3"); 




        String HaberKodu5 = "";
        String Aciklama5 = "";

        foreach (XmlNode node5 in ReadInDocument5.SelectNodes(".//Aciklamalar/Aciklama"))
        {
        SqlCommand komut1 = new SqlCommand("Select*from gelenhaberaciklama where HaberKodu=@HaberKodu", con5);
        komut1.Parameters.AddWithValue("@HaberKodu", node5.Attributes["HaberKodu"].InnerText);
    SqlDataReader oku = komut1.ExecuteReader();
    if (oku.HasRows)
    {

    }
    else
    {
        HaberKodu5 = node5.Attributes["HaberKodu"].InnerText;
        Aciklama5 = ((node5).FirstChild).Value; 
        SqlCommand cmd5 = new SqlCommand(strQuery5);
        cmd5.CommandType = CommandType.Text;
        cmd5.Connection = con5;
        cmd5.Parameters.AddWithValue("@HaberKodu5", HaberKodu5.ToString());
        cmd5.Parameters.AddWithValue("@Aciklama5", Capitalize(Aciklama5.ToString()));
        cmd5.ExecuteNonQuery();

    }
    oku.Dispose();
        }
        con5.Close();
        con5.Dispose(); 
        Response.Redirect("Haberler.aspx");`
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.