Archive for dotNet(.Net)

Simple Program to create XML from table in database, .NET

Hm..after I think for a while, i decide to post this simple program..
But I just want to share my knowledge. Actually I got this from internet too..but I just hope, just hope that I can help someone who really want to make xml from database.

Okey, If I want to make xml from database and show it in GridView (in case for web application /asp.net), these are the steps..

  1. Create your new Web site application and then open Default.aspx.cs or double click on Default.aspx. On formLoad type this code (better you type so you can more understand it):
    Include these library:

    using System.Data.SqlClient;
    using System.Xml;
    using System.Xml.Serialization;
    using System.Collections.Generic;
    using System.IO;

    protected void Page_Load(object sender, EventArgs e) {
    DataSet ds = new  DataSet();
    String constr = “Data Source = (local); Initial Catalog=[Choose ur db name] User ID = sa;
    Password = [ur db passwd]“
    ;
    SqlConnection newConn =  new SqlConnection(constr);
    String strcmd = “select * from [ur table]“;
    SqlDataAdapter da = new SqlDataAdapter(strcmd, newConn);
    da.Fill(ds, “[ur table]“);
    ds.WriteXml(MapPath(“FileName.xml”));
    }

  2. Then create the interface by dragging GridView and a Button from toolbox to Default.aspx.
  3. Double click on your button (it will show file Default.aspx.cs) and type this code

    protected void Button1_Click(object sender, EventArgs e) {
    XmlDataDocument doc = null;
    DataSet ds = new DataSet();
    string path =  Path.Combine(Request.PhysicalApplicationPath, “FileName.xml”);
    ds.ReadXml(path);
    doc = new XmlDataDocument(ds);
    GridView1.DataSource = ds;
    GridView1.DataBind();
    }

  4. Build your web site and then press the button, the data will show in the GridView. Good Luck!

If  you want to use Windows Application, it’s very simple. You just need to change the code inside the Button event. Look at this code

  1. Type this code inside button1 event

    private void button1_Click(object sender, EventArgs e) {
    XmlDataDocument doc = null;
    DataSet ds = new DataSet();
    ds.ReadXml(Application.StartupPath + @”\FileName.xml”);
    doc = new XmlDataDocument(ds);
    dataGridView1.DataSource = ds.Table[0];
    }

  2. That’s all, but don’t forget to move your xml file to bin\Debug\FileName.xml. Good Luck for you guys.

Remember this is just one of the way to create xml from database and show it in GridView, there are so many ways. I hope these simple code can help you.

Comments (12)

Ajax Control Toolkit Installation in Ms. Visual Studio 2005

Kemarin aku cari-cari langkah2 untuk menginstal ajax. Hehhe..maklum udah lupa, nih aku bagi2 yacs…semoga sukses semuanya…

by Nannette Thacker

To install the Ajax Control Toolkit, you need:
AjaxControlToolkit.zip
ASPAjaxExtSetup.msi

first download the zip file of AjaxControlToolkit and ASPAjaxExtSetup (you can download it from internet)

Install ASPAJAXExtSetup.msi and then unzip the files AjaxControlToolkit.zip into any directory. Give it a name like “AjaxControlToolkit.”  

Open your Visual Web Developer and right click in the Toolbox area. Select “Add Tab.” 

Name the tab with something like “Ajax Tookit.”  

Right click the new tab area, and select “Choose Items…” 

This will bring up a dialog box to “Choose Toolbox Items.” Select the “Browse” button. 

Browse to the directory where you unzipped the Ajax Toolkit files. There is a “SampleWebSite” directory within your “AjaxControlToolkit” directory. Browse to the “Bin” directory within the “SampleWebSite” directory. 

Find and select to open the “AjaxControlToolkit.dll” file. 

The Choose Toolbox Items dialog will appear, this time with the Ajax Tookit controls selected. Select the “OK” button. 

Open or create a web form within your project. Now when you open your toolbox, you will see all of the Ajax Control Toolkit controls, ready for use within your applications. 
 

~~~~~~May your dreams be in ASP.net!~~~~~~

You can download the document here.

ajax-control-toolkit-installation

 

Comments (10)