将数据从xml存储到数据库 [英] Store data from xml to database

查看:107
本文介绍了将数据从xml存储到数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将数据从xml存储到数据库.首先检查数据库中是否不存在相同的数据,然后将其保存为正确的格式.请帮忙!!!
我正在这样做:

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 :

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)
        {
           
        }

}
}


当我运行此代码时,发生错误,找不到gridview?
有人请帮忙!!!!!!


When I run this code error occurs that gridview is not found?
Some body please help!!!!!!

推荐答案

您是否在名为"Gridview"的表单上创建了GridView?检查并记住C#区分大小写.因此,如果您将conrtol称为"gridview"或"gridView"或"Gridview1",则将找不到它.

看来您确实有一些问题-由于格式正确,请尝试使用CTRL + K,D重新格式化您的文档.可能是您在其他地方缺少使编译器感到困惑的内容.如果您无法重新格式化以使大括号对齐且缩进正确,则请先查找原因.
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.


这篇关于将数据从xml存储到数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆