Click here to Skip to main content
16,021,115 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to store data from xml to database. 1st check if same data doesn't exist in database then save it in a proper format. Please help!!!
I am doing this :
C#
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Xml;
using System.Data.SqlClient;
 

namespace WindowsFormsApplicationtry
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void label1_Click(object sender, EventArgs e)
        {

        }

        private void button1_Click(object sender, EventArgs e)
        {
            XmlWriter writer = XmlWriter.Create(@"C:\Users\syed\Desktop\SIEM\xml.xml");

            writer.WriteStartElement("QUERY");

            writer.WriteStartElement("IT");
            writer.WriteAttributeString("macName", textBox1.Text);
            writer.WriteElementString("Generated_source", textBox2.Text);
            writer.WriteElementString("TimeStemp", textBox3.Text);
            writer.WriteEndElement();
            
      writer.Close();}

        private void btnReader_Click_1(object sender, EventArgs e)
        {
         string myXMLfile = @"C:\Users\syed\Desktop\SIEM\xml.xml";
    DataSet ds = new DataSet();
    // Create new FileStream with which to read the schema.
    System.IO.FileStream fsReadXml = new System.IO.FileStream 
        (myXMLfile, System.IO.FileMode.Open);
    try
    {
        ds.ReadXml(fsReadXml);
        DataTable dbTable1 = ds.Tables[0];
       Gridview.DataSource = dbTable1;        
    }
    catch (Exception ex)
    {
 MessageBox.Show(ex.ToString());
    }
    finally
    {
 fsReadXml.Close();
    }
     }

        private void Form1_Load(object sender, EventArgs e)
        {
        //    // TODO: This line of code loads data into the 'database1DataSet1.xmlread' table. You can move, or remove it, as needed.
        //    this.xmlreadTableAdapter.Fill(this.database1DataSet1.xmlread);
        //    // TODO: This line of code loads data into the 'dataSet1.Credit' table. You can move, or remove it, as needed.
        //    this.creditTableAdapter.Fill(this.dataSet1.Credit);

        }

        private void GridView_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
           
        }

}
}

When I run this code error occurs that gridview is not found?
Some body please help!!!!!!
Posted
Updated 9-Oct-10 22:39pm
v5
Comments
Sandeep Mewara 10-Oct-10 4:40am    
Well, when and where you get that error? It doesn't look like it should be the error.
OriginalGriff 10-Oct-10 10:12am    
"yea icreated a GridView on your form called "Gridview"
n also try CTRL+K isn't working plzz plz zz help me out plz - jia123m 1 hour ago"
Try holding CTRL press K then D, then release CTRL. It should reformat your code to readable indents.
Are you sure you called it "Gridview"? Start a new line below the line "Gridview.DataSource = dbTable1;" and type "G" - intellisense shoudl start to autocomplete. Continue with "rid" and see if "Gridview" with that exact case is in the list. If not, what is?

1 solution

Have you created a GridView on your form called "Gridview"? Check, and remember that C# is case sensitive. So if your conrtol is called "gridview" or "gridView" or "Gridview1" it will not be found.

It does look like you have some problems - try using CTRL+K, D to reformat your document as the formatting is well out. It may be that you are missing something elsewhere that is confusing the compiler. If you cannot reformat to get the braces lined up and indentation correct then look for why first.
 
Share this answer
 
Comments
jia123m 10-Oct-10 9:00am    
yea icreated a GridView on your form called "Gridview"
n also try CTRL+K isn't working plzz plz zz help me out plz

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900