Click here to Skip to main content
15,918,211 members
Please Sign up or sign in to vote.
1.00/5 (4 votes)
See more:
I am doing a quiz game ,data is saved in xml file.Can you introduce to me?Can you give me a code project to study?
Posted
Updated 12-Apr-11 19:17pm
v2
Comments
Sergey Alexandrovich Kryukov 12-Apr-11 23:33pm    
Are you doing a quiz game or you need to introduction to it? Those are "contradictory paragraphs"...
There is nothing to introduce, just sit down and do it. Ask a question if you face any problem.
Web or windows application?
--SA

...boring stuff... who need a quiz?..
chandan kumar 22-Aug-13 8:10am    
@rogerminh have u get the solution .I have same problem in android .if,yes then please help me.
Thank's
rogerminh2401 12-Apr-11 23:52pm    
Can you give me a code quiz game?
CPallini 13-Apr-11 1:17am    
Nope, I'm going to give you a 'GimmeCode' tag, though.
Tarun.K.S 13-Apr-11 2:00am    
Lol!!

1 solution

I had developed a quiz game like KBC few years earlier. Not complete but its coding part is as below:

GameForm (Form1):
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.IO;	// for Filestream 
using System.Xml;
using System.Xml.XPath;
using System.Xml.Serialization;
namespace KBC1
{
	/// <summary>
	/// Summary description for Form1.
	/// </summary>
	public class Form1 : System.Windows.Forms.Form
	{
		private System.Windows.Forms.Button button1;
		private System.Windows.Forms.Button button2;
		private System.Windows.Forms.Button button3;
		private System.Windows.Forms.Button button4;
		private System.Windows.Forms.GroupBox groupBox1;
		private System.Windows.Forms.ListBox listBox1;
		
		private System.Windows.Forms.Button btnAddQues;
		private System.Windows.Forms.Button btnExit;
		private System.Windows.Forms.Label label1;
		private System.Windows.Forms.Button btnStart;
		private System.ComponentModel.IContainer components;
		
		public System.Data.DataSet myds;
		public System.Data.DataTable mytable;
		public int n;
		public XmlDataDocument doc; 
		public XPathNavigator XPNav;
		private System.Windows.Forms.DataGrid dataGrid1;
		// Get path of the xml file from the system 
		public string xmlFPath;
		public Form1()
		{
			//
			// Required for Windows Form Designer support
			//
			InitializeComponent();
		}
		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if (components != null) 
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}
		#region Windows Form Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
			this.button1 = new System.Windows.Forms.Button();
			this.button2 = new System.Windows.Forms.Button();
			this.button3 = new System.Windows.Forms.Button();
			this.button4 = new System.Windows.Forms.Button();
			this.groupBox1 = new System.Windows.Forms.GroupBox();
			this.listBox1 = new System.Windows.Forms.ListBox();
			this.btnAddQues = new System.Windows.Forms.Button();
			this.btnExit = new System.Windows.Forms.Button();
			this.btnStart = new System.Windows.Forms.Button();
			this.label1 = new System.Windows.Forms.Label();
			this.dataGrid1 = new System.Windows.Forms.DataGrid();
			this.groupBox1.SuspendLayout();
			((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).BeginInit();
			this.SuspendLayout();
			// 
			// button1
			// 
			this.button1.BackColor = System.Drawing.Color.LightSalmon;
			this.button1.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
			this.button1.Font = new System.Drawing.Font("Microsoft Sans Serif", 10F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.button1.Location = new System.Drawing.Point(112, 32);
			this.button1.Name = "button1";
			this.button1.Size = new System.Drawing.Size(272, 50);
			this.button1.TabIndex = 0;
			this.button1.Text = "Option1";
			this.button1.Click += new System.EventHandler(this.button1_Click);
			// 
			// button2
			// 
			this.button2.BackColor = System.Drawing.Color.LightSalmon;
			this.button2.Location = new System.Drawing.Point(528, 32);
			this.button2.Name = "button2";
			this.button2.Size = new System.Drawing.Size(264, 50);
			this.button2.TabIndex = 1;
			this.button2.Text = "Option2";
			this.button2.Click += new System.EventHandler(this.button2_Click);
			// 
			// button3
			// 
			this.button3.BackColor = System.Drawing.Color.LightSalmon;
			this.button3.Location = new System.Drawing.Point(112, 128);
			this.button3.Name = "button3";
			this.button3.Size = new System.Drawing.Size(272, 50);
			this.button3.TabIndex = 2;
			this.button3.Text = "Option3";
			this.button3.Click += new System.EventHandler(this.button3_Click);
			// 
			// button4
			// 
			this.button4.BackColor = System.Drawing.Color.LightSalmon;
			this.button4.Location = new System.Drawing.Point(528, 128);
			this.button4.Name = "button4";
			this.button4.Size = new System.Drawing.Size(264, 50);
			this.button4.TabIndex = 3;
			this.button4.Text = "Option4";
			this.button4.Click += new System.EventHandler(this.button4_Click);
			// 
			// groupBox1
			// 
			this.groupBox1.BackColor = System.Drawing.Color.Coral;
			this.groupBox1.Controls.AddRange(new System.Windows.Forms.Control[] {
																					this.button1,
																					this.button2,
																					this.button3,
																					this.button4});
			this.groupBox1.Font = new System.Drawing.Font("Microsoft Sans Serif", 10F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.groupBox1.Location = new System.Drawing.Point(40, 440);
			this.groupBox1.Name = "groupBox1";
			this.groupBox1.Size = new System.Drawing.Size(920, 208);
			this.groupBox1.TabIndex = 4;
			this.groupBox1.TabStop = false;
			this.groupBox1.Text = "groupBox1";
			this.groupBox1.Enter += new System.EventHandler(this.groupBox1_Enter);
			// 
			// listBox1
			// 
			this.listBox1.BackColor = System.Drawing.Color.LightSalmon;
			this.listBox1.Font = new System.Drawing.Font("Microsoft Sans Serif", 10F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.listBox1.ForeColor = System.Drawing.Color.DarkRed;
			this.listBox1.ItemHeight = 16;
			this.listBox1.Items.AddRange(new object[] {
														  "Winning Amount",
														  "1000",
														  "2000",
														  "5000",
														  "10000",
														  "20000",
														  "50000",
														  "100000",
														  "1000000",
														  "2500000",
														  "5000000",
														  "10000000"});
			this.listBox1.Location = new System.Drawing.Point(824, 192);
			this.listBox1.Name = "listBox1";
			this.listBox1.RightToLeft = System.Windows.Forms.RightToLeft.Yes;
			this.listBox1.Size = new System.Drawing.Size(128, 212);
			this.listBox1.TabIndex = 5;
			this.listBox1.SelectedIndexChanged += new System.EventHandler(this.listBox1_SelectedIndexChanged);
			// 
			// btnAddQues
			// 
			this.btnAddQues.BackColor = System.Drawing.Color.SandyBrown;
			this.btnAddQues.Font = new System.Drawing.Font("Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.btnAddQues.Location = new System.Drawing.Point(376, 48);
			this.btnAddQues.Name = "btnAddQues";
			this.btnAddQues.Size = new System.Drawing.Size(184, 40);
			this.btnAddQues.TabIndex = 7;
			this.btnAddQues.Text = "Add new Question";
			this.btnAddQues.Click += new System.EventHandler(this.btnAddQues_Click);
			// 
			// btnExit
			// 
			this.btnExit.BackColor = System.Drawing.Color.OrangeRed;
			this.btnExit.Font = new System.Drawing.Font("Microsoft Sans Serif", 15F, (System.Drawing.FontStyle.Bold | System.Drawing.FontStyle.Italic), System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.btnExit.ForeColor = System.Drawing.Color.Snow;
			this.btnExit.Location = new System.Drawing.Point(824, 48);
			this.btnExit.Name = "btnExit";
			this.btnExit.Size = new System.Drawing.Size(128, 40);
			this.btnExit.TabIndex = 8;
			this.btnExit.Text = "Exit";
			this.btnExit.Click += new System.EventHandler(this.btnExit_Click);
			// 
			// btnStart
			// 
			this.btnStart.BackColor = System.Drawing.Color.Green;
			this.btnStart.Font = new System.Drawing.Font("Microsoft Sans Serif", 15F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.btnStart.ForeColor = System.Drawing.SystemColors.HighlightText;
			this.btnStart.Location = new System.Drawing.Point(40, 48);
			this.btnStart.Name = "btnStart";
			this.btnStart.Size = new System.Drawing.Size(144, 40);
			this.btnStart.TabIndex = 9;
			this.btnStart.Text = "Start Game";
			this.btnStart.Click += new System.EventHandler(this.btnStart_Click);
			// 
			// label1
			// 
			this.label1.BackColor = System.Drawing.Color.Black;
			this.label1.Font = new System.Drawing.Font("Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.label1.ForeColor = System.Drawing.SystemColors.Menu;
			this.label1.Location = new System.Drawing.Point(88, 192);
			this.label1.Name = "label1";
			this.label1.Size = new System.Drawing.Size(680, 208);
			this.label1.TabIndex = 10;
			this.label1.Text = "label1";
			this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
			// 
			// dataGrid1
			// 
			this.dataGrid1.DataMember = "";
			this.dataGrid1.HeaderForeColor = System.Drawing.SystemColors.ControlText;
			this.dataGrid1.Location = new System.Drawing.Point(160, 104);
			this.dataGrid1.Name = "dataGrid1";
			this.dataGrid1.Size = new System.Drawing.Size(536, 80);
			this.dataGrid1.TabIndex = 11;
			// 
			// Form1
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
			this.BackColor = System.Drawing.Color.Maroon;
			this.ClientSize = new System.Drawing.Size(944, 558);
			this.Controls.AddRange(new System.Windows.Forms.Control[] {
																		  this.dataGrid1,
																		  this.label1,
																		  this.btnStart,
																		  this.btnExit,
																		  this.btnAddQues,
																		  this.listBox1,
																		  this.groupBox1});
			this.Name = "Form1";
			this.Text = "Form1";
			this.WindowState = System.Windows.Forms.FormWindowState.Maximized;
			this.Load += new System.EventHandler(this.Form1_Load);
			this.groupBox1.ResumeLayout(false);
			((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).EndInit();
			this.ResumeLayout(false);
		}
		#endregion
		/// <summary>
		/// The main entry point for the application.
		/// </summary>
		[STAThread]
		static void Main() 
		{
			Application.Run(new Form1());
		}
		private void Form1_Load(object sender, System.EventArgs e)
		{
			listBox1.SelectedIndex=0;
			mytable = new DataTable("KBC");
			DataColumn col1 = new DataColumn("Question");
			col1.DataType = System.Type.GetType("System.String");
			this.mytable.Columns.Add(col1);
			DataColumn col2 = new DataColumn("opt1");
			col2.DataType = System.Type.GetType("System.String");
			this.mytable.Columns.Add(col2);
			DataColumn col3 = new DataColumn("opt2");
			col3.DataType = System.Type.GetType("System.String");
			this.mytable.Columns.Add(col3);
			DataColumn col4 = new DataColumn("opt3");
			col4.DataType = System.Type.GetType("System.String");
			this.mytable.Columns.Add(col4);
			DataColumn col5 = new DataColumn("opt4");
			col5.DataType = System.Type.GetType("System.String");
			this.mytable.Columns.Add(col5);
			DataColumn col6 = new DataColumn("opt5");
			col6.DataType = System.Type.GetType("System.String");
			this.mytable.Columns.Add(col6);
			myds = new DataSet("myDS"); 
			// Add Table to DataSet
			this.myds.Tables.Add(mytable);
			// Get path of the xml file from the system 
			xmlFPath = Application.StartupPath;		
	if (File.Exists(xmlFPath + "\\KBCXML1.xml"))	// check file's existance  
	{
		this.myds.ReadXmlSchema(xmlFPath + "\\KBCXML1.xml");
		this.myds.ReadXml(xmlFPath + "\\KBCXML1.xml"); 	
//*************//
				dataGrid1.DataSource = myds; 
				dataGrid1.DataMember = "KBC";
//*************//
			}
			else
			{
				label1.Text = "Resource XML file not found.";
			} 
		}

		private void button1_Click(object sender, System.EventArgs e)
		{
			button1.BackColor = System.Drawing.Color.Blue;
			string str = button1.Text;
			GetResult(str); 
		}
		private void button2_Click(object sender, System.EventArgs e)
		{
			button2.BackColor = System.Drawing.Color.Blue;
		}
		private void button3_Click(object sender, System.EventArgs e)
		{
			button3.BackColor = System.Drawing.Color.Blue;
		}
		private void button4_Click(object sender, System.EventArgs e)
		{
			button4.BackColor = System.Drawing.Color.Blue;
		}
		private void btnAddQues_Click(object sender, System.EventArgs e)
		{
			Form QForm = new AddForm();
			QForm.Show();
		}
		private void groupBox1_Enter(object sender, System.EventArgs e)
		{
		
		}
		private void listBox1_SelectedIndexChanged(object sender, System.EventArgs e)
		{
		
		}
		private void btnExit_Click(object sender, System.EventArgs e)
		{
			this.Close();
		}
		private void label1_Click(object sender, System.EventArgs e)
		{
		
		}
		private void btnStart_Click(object sender, System.EventArgs e)
		{
/*			doc = new XmlDataDocument();	// where doc is an XmlDataDocument's object (public)
			doc.DataSet.ReadXmlSchema(xmlFPath + "\\KBCXML1.xml"); 
			doc.Load(xmlFPath + "\\KBCXML1.xml"); 
			XPNav = doc.CreateNavigator();
			XPNav.MoveToRoot();
			
			string str=""; 
			XPathNodeIterator XPIter;
			XPIter = XPNav.Select("desendant::Question"); 
			while(XPIter.MoveNext())
				str += XPIter.Current.Value + "<br/>";
			label1.Text = str; 
//			XmlElement xElement;
//			xElement = doc.GetElementFromRow(mrow);
//			label1.Text = xElement.OuterXml;
*/ 						
			
			foreach(DataRow mrow in myds.Tables[0].Rows) 
			{
				label1.Text =  mrow["Question"].ToString(); 
				button1.Text = mrow["opt1"].ToString();
				button2.Text = mrow["opt2"].ToString();
				button3.Text = mrow["opt3"].ToString();
				button4.Text = mrow["opt4"].ToString();
//			}
//	}
		public void GetResult(string selectedOption)
		{
		
		}
	}
}
AddForm:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.IO;	// for Filestream 
using System.Data;
using System.Xml;
using System.Xml.XPath;
using System.Xml.Serialization;
namespace KBC1
{
	/// <summary>
	/// Summary description for AddForm.
	/// </summary>
	public class AddForm : System.Windows.Forms.Form
	{
		private System.Windows.Forms.Label label1;
		private System.Windows.Forms.Label label2;
		private System.Windows.Forms.Label label3;
		private System.Windows.Forms.Label label4;
		private System.Windows.Forms.Label label5;
		private System.Windows.Forms.Label label6;
		private System.Windows.Forms.TextBox textBox1;
		private System.Windows.Forms.TextBox textBox2;
		private System.Windows.Forms.TextBox textBox3;
		private System.Windows.Forms.TextBox textBox4;
		private System.Windows.Forms.TextBox textBox5;
		private System.Windows.Forms.TextBox textBox6;
		private System.Windows.Forms.Label label7;
		private System.Windows.Forms.Button btnSave;
		public System.Data.DataSet ds;
		public System.Data.DataTable dt; 
		private System.Windows.Forms.DataGrid datagrid1;
		private System.Windows.Forms.Button btnReturn;
		private System.Windows.Forms.Label label8;
	
		/// <summary>
		/// Required designer variable.
		/// </summary>
		private System.ComponentModel.Container components = null;
		public AddForm()
		{
			//
			// Required for Windows Form Designer support
			//
			InitializeComponent();
			dt = new System.Data.DataTable("KBC");	// my code  starts 
			
			// Create Columns for the table
			DataColumn col1 = new System.Data.DataColumn("Question");
				col1.DataType = System.Type.GetType("System.String");
				this.dt.Columns.Add(col1);
			DataColumn col2 = new System.Data.DataColumn("opt1");
				col2.DataType = System.Type.GetType("System.String");
				this.dt.Columns.Add(col2);
			
			DataColumn col3 = new System.Data.DataColumn("opt2");
				col3.DataType = System.Type.GetType("System.String");
				this.dt.Columns.Add(col3);
			
			DataColumn col4 = new System.Data.DataColumn("opt3");
				col4.DataType = System.Type.GetType("System.String");
				this.dt.Columns.Add(col4);
			DataColumn col5 = new System.Data.DataColumn("opt4");
				col5.DataType = System.Type.GetType("System.String");
				this.dt.Columns.Add(col5);
			
				DataColumn col6 = new System.Data.DataColumn("Result"); 
				col6.DataType = System.Type.GetType("System.String");
				this.dt.Columns.Add(col6);
 
			ds = new DataSet("myDS"); 
			// Add Table to DataSet
			this.ds.Tables.Add(dt);
			
			// Get path of the xml file from the system 
			string xmlFPath = Application.StartupPath;
			
			if(File.Exists(xmlFPath + "\\KBCXML1.xml"))	// check file's existance  
			{
			//	this.ds.ReadXmlSchema("H:\\My DotNet\\KBC1\\" + "KBCXML1.xml"); 
				this.ds.ReadXmlSchema(xmlFPath + "\\KBCXML1.xml");
				this.ds.ReadXml(xmlFPath + "\\KBCXML1.xml"); 	
	//			this.ds.ReadXml("H:\\My DotNet\\KBC1\\" + "KBCXML1.xml");
				this.datagrid1.DataSource=ds;
				this.datagrid1.DataMember = "KBC";
			}
			else
			{
				label8.Visible = true; 
				label8.Text = "Resource XML file not found.";
				btnSave.Enabled = false;
			} 
		}
		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if(components != null)
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}
		#region Windows Form Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
			this.label1 = new System.Windows.Forms.Label();
			this.label2 = new System.Windows.Forms.Label();
			this.label3 = new System.Windows.Forms.Label();
			this.label4 = new System.Windows.Forms.Label();
			this.label5 = new System.Windows.Forms.Label();
			this.label6 = new System.Windows.Forms.Label();
			this.textBox1 = new System.Windows.Forms.TextBox();
			this.textBox2 = new System.Windows.Forms.TextBox();
			this.textBox3 = new System.Windows.Forms.TextBox();
			this.textBox4 = new System.Windows.Forms.TextBox();
			this.textBox5 = new System.Windows.Forms.TextBox();
			this.textBox6 = new System.Windows.Forms.TextBox();
			this.btnSave = new System.Windows.Forms.Button();
			this.label7 = new System.Windows.Forms.Label();
			this.datagrid1 = new System.Windows.Forms.DataGrid();
			this.btnReturn = new System.Windows.Forms.Button();
			this.label8 = new System.Windows.Forms.Label();
			((System.ComponentModel.ISupportInitialize)(this.datagrid1)).BeginInit();
			this.SuspendLayout();
			// 
			// label1
			// 
			this.label1.BackColor = System.Drawing.SystemColors.InactiveCaptionText;
			this.label1.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.label1.Location = new System.Drawing.Point(48, 104);
			this.label1.Name = "label1";
			this.label1.TabIndex = 0;
			this.label1.Text = "QUESTION:";
			this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
			// 
			// label2
			// 
			this.label2.BackColor = System.Drawing.SystemColors.InactiveCaptionText;
			this.label2.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.label2.Location = new System.Drawing.Point(48, 160);
			this.label2.Name = "label2";
			this.label2.TabIndex = 1;
			this.label2.Text = "OPTION1:";
			this.label2.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
			// 
			// label3
			// 
			this.label3.BackColor = System.Drawing.SystemColors.InactiveCaptionText;
			this.label3.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.label3.Location = new System.Drawing.Point(48, 208);
			this.label3.Name = "label3";
			this.label3.TabIndex = 2;
			this.label3.Text = "OPTION2:";
			this.label3.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
			// 
			// label4
			// 
			this.label4.BackColor = System.Drawing.SystemColors.InactiveCaptionText;
			this.label4.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.label4.Location = new System.Drawing.Point(48, 256);
			this.label4.Name = "label4";
			this.label4.TabIndex = 3;
			this.label4.Text = "OPTION3:";
			this.label4.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
			// 
			// label5
			// 
			this.label5.BackColor = System.Drawing.SystemColors.InactiveCaptionText;
			this.label5.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.label5.Location = new System.Drawing.Point(48, 304);
			this.label5.Name = "label5";
			this.label5.TabIndex = 4;
			this.label5.Text = "OPTION4:";
			this.label5.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
			// 
			// label6
			// 
			this.label6.BackColor = System.Drawing.SystemColors.InactiveCaptionText;
			this.label6.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.label6.Location = new System.Drawing.Point(48, 352);
			this.label6.Name = "label6";
			this.label6.TabIndex = 5;
			this.label6.Text = "RESULT:";
			this.label6.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
			// 
			// textBox1
			// 
			this.textBox1.BackColor = System.Drawing.SystemColors.InactiveCaptionText;
			this.textBox1.Location = new System.Drawing.Point(184, 104);
			this.textBox1.Name = "textBox1";
			this.textBox1.Size = new System.Drawing.Size(768, 20);
			this.textBox1.TabIndex = 6;
			this.textBox1.Text = "";
			// 
			// textBox2
			// 
			this.textBox2.BackColor = System.Drawing.SystemColors.InactiveCaptionText;
			this.textBox2.Location = new System.Drawing.Point(184, 160);
			this.textBox2.Name = "textBox2";
			this.textBox2.Size = new System.Drawing.Size(224, 20);
			this.textBox2.TabIndex = 7;
			this.textBox2.Text = "";
			// 
			// textBox3
			// 
			this.textBox3.BackColor = System.Drawing.SystemColors.InactiveCaptionText;
			this.textBox3.Location = new System.Drawing.Point(184, 208);
			this.textBox3.Name = "textBox3";
			this.textBox3.Size = new System.Drawing.Size(224, 20);
			this.textBox3.TabIndex = 8;
			this.textBox3.Text = "";
			// 
			// textBox4
			// 
			this.textBox4.BackColor = System.Drawing.SystemColors.InactiveCaptionText;
			this.textBox4.Location = new System.Drawing.Point(184, 256);
			this.textBox4.Name = "textBox4";
			this.textBox4.Size = new System.Drawing.Size(224, 20);
			this.textBox4.TabIndex = 9;
			this.textBox4.Text = "";
			// 
			// textBox5
			// 
			this.textBox5.BackColor = System.Drawing.SystemColors.InactiveCaptionText;
			this.textBox5.Location = new System.Drawing.Point(184, 304);
			this.textBox5.Name = "textBox5";
			this.textBox5.Size = new System.Drawing.Size(224, 20);
			this.textBox5.TabIndex = 10;
			this.textBox5.Text = "";
			// 
			// textBox6
			// 
			this.textBox6.BackColor = System.Drawing.SystemColors.InactiveCaptionText;
			this.textBox6.Location = new System.Drawing.Point(184, 352);
			this.textBox6.Name = "textBox6";
			this.textBox6.Size = new System.Drawing.Size(224, 20);
			this.textBox6.TabIndex = 11;
			this.textBox6.Text = "";
			// 
			// btnSave
			// 
			this.btnSave.BackColor = System.Drawing.SystemColors.ActiveBorder;
			this.btnSave.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.btnSave.Location = new System.Drawing.Point(184, 408);
			this.btnSave.Name = "btnSave";
			this.btnSave.Size = new System.Drawing.Size(104, 23);
			this.btnSave.TabIndex = 12;
			this.btnSave.Text = "Save";
			this.btnSave.Click += new System.EventHandler(this.btnSave_Click);
			// 
			// label7
			// 
			this.label7.BackColor = System.Drawing.Color.MistyRose;
			this.label7.Font = new System.Drawing.Font("Microsoft Sans Serif", 12F, (System.Drawing.FontStyle.Bold | System.Drawing.FontStyle.Italic), System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.label7.Location = new System.Drawing.Point(248, 24);
			this.label7.Name = "label7";
			this.label7.Size = new System.Drawing.Size(360, 23);
			this.label7.TabIndex = 13;
			this.label7.Text = "Questions  Form";
			this.label7.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
			// 
			// datagrid1
			// 
			this.datagrid1.AlternatingBackColor = System.Drawing.Color.GhostWhite;
			this.datagrid1.BackColor = System.Drawing.Color.GhostWhite;
			this.datagrid1.BackgroundColor = System.Drawing.Color.Lavender;
			this.datagrid1.BorderStyle = System.Windows.Forms.BorderStyle.None;
			this.datagrid1.CaptionBackColor = System.Drawing.Color.RoyalBlue;
			this.datagrid1.CaptionForeColor = System.Drawing.Color.White;
			this.datagrid1.DataMember = "";
			this.datagrid1.FlatMode = true;
			this.datagrid1.Font = new System.Drawing.Font("Tahoma", 8F);
			this.datagrid1.ForeColor = System.Drawing.Color.MidnightBlue;
			this.datagrid1.GridLineColor = System.Drawing.Color.RoyalBlue;
			this.datagrid1.HeaderBackColor = System.Drawing.Color.MidnightBlue;
			this.datagrid1.HeaderFont = new System.Drawing.Font("Tahoma", 8F, System.Drawing.FontStyle.Bold);
			this.datagrid1.HeaderForeColor = System.Drawing.Color.Lavender;
			this.datagrid1.LinkColor = System.Drawing.Color.Teal;
			this.datagrid1.Location = new System.Drawing.Point(424, 144);
			this.datagrid1.Name = "datagrid1";
			this.datagrid1.ParentRowsBackColor = System.Drawing.Color.Lavender;
			this.datagrid1.ParentRowsForeColor = System.Drawing.Color.MidnightBlue;
			this.datagrid1.SelectionBackColor = System.Drawing.Color.Teal;
			this.datagrid1.SelectionForeColor = System.Drawing.Color.PaleGreen;
			this.datagrid1.Size = new System.Drawing.Size(592, 552);
			this.datagrid1.TabIndex = 14;
			// 
			// btnReturn
			// 
			this.btnReturn.BackColor = System.Drawing.SystemColors.ActiveBorder;
			this.btnReturn.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.btnReturn.ForeColor = System.Drawing.Color.Red;
			this.btnReturn.Location = new System.Drawing.Point(880, 24);
			this.btnReturn.Name = "btnReturn";
			this.btnReturn.TabIndex = 15;
			this.btnReturn.Text = "RETURN";
			this.btnReturn.Click += new System.EventHandler(this.btnReturn_Click);
			// 
			// label8
			// 
			this.label8.BackColor = System.Drawing.SystemColors.ControlText;
			this.label8.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.label8.ForeColor = System.Drawing.SystemColors.HighlightText;
			this.label8.Location = new System.Drawing.Point(72, 472);
			this.label8.Name = "label8";
			this.label8.Size = new System.Drawing.Size(312, 23);
			this.label8.TabIndex = 16;
			this.label8.Text = "label8";
			this.label8.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
			this.label8.Visible = false;
			// 
			// AddForm
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
			this.BackColor = System.Drawing.SystemColors.Desktop;
			this.ClientSize = new System.Drawing.Size(952, 558);
			this.Controls.AddRange(new System.Windows.Forms.Control[] {
																		  this.label8,
																		  this.btnReturn,
																		  this.datagrid1,
																		  this.label7,
																		  this.btnSave,
																		  this.textBox6,
																		  this.textBox5,
																		  this.textBox4,
																		  this.textBox3,
																		  this.textBox2,
																		  this.textBox1,
																		  this.label6,
																		  this.label5,
																		  this.label4,
																		  this.label3,
																		  this.label2,
																		  this.label1});
			this.MaximizeBox = false;
			this.MinimizeBox = false;
			this.Name = "AddForm";
			this.ShowInTaskbar = false;
			this.Text = "AddForm";
			this.WindowState = System.Windows.Forms.FormWindowState.Maximized;
			((System.ComponentModel.ISupportInitialize)(this.datagrid1)).EndInit();
			this.ResumeLayout(false);
		}
		#endregion
		private void btnSave_Click(object sender, System.EventArgs e)
		{	
			// Get path of the xml file from the system 
			string xmlFPath  = Application.StartupPath; 
			string fileName = xmlFPath+"\\KBCXML1.xml";
			//string fileName = "H:\\My DotNet\\KBC1\\KBCXML1.xml";
			if(File.Exists(xmlFPath + "\\KBCXML1.xml"))	// check file's existance  
			{
				DataRow newRow;
				newRow = this.ds.Tables[0].NewRow();
				newRow[0] = this.textBox1.Text;
				newRow[1] = this.textBox2.Text;
				newRow[2] = this.textBox3.Text;
				newRow[3] = this.textBox4.Text;
				newRow[4] = this.textBox5.Text;
				newRow[5] = this.textBox6.Text;
				
				this.ds.Tables[0].Rows.Add(newRow); // update table
				this.ds.WriteXml(fileName);		// update xml file also
				
				// Now store table's records to DataGrid
				this.datagrid1.DataSource = this.ds;
				this.datagrid1.DataMember = "KBC";
				this.datagrid1.Refresh();
			}
		}
		
		private void btnReturn_Click(object sender, System.EventArgs e)
		{
			this.Close();
		}
		}
	}


Hope it will be useful for you.
 
Share this answer
 
Comments
CPallini 13-Apr-11 1:16am    
You use poor names (I know, the ones VS automatically provides) for your variables.

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