Number of buttons based on number of collums in XML


Generate a number of buttons based on XML file
The Code that generates the buttons.
The for loop doesn’t work for the buttons.

using UnityEngine;
using System.Collections;

public class Dialog : MonoBehaviour {
	//textReader = GameObject.FindObjectOfType(typeof(textReader)) as textReader;
	// Use this for initialization
	void Start () {
	// Update is called once per frame
	void Update () {

	void OnGUI (){
		// Constrain all drawing to be within a 800x600 pixel area centered on the screen.
		GUI.BeginGroup (new Rect (Screen.width / 2 - 400, Screen.height / 2 - 300, 800, 600));
		GUI.Box (new Rect (0,0,800,600),"");

			for(int x = 0;x <;x++)
				GUI.Button(new Rect(0,x*20,20,10),textReader.option1);

		GUI.EndGroup ();
		//Either with a toolbar:


The code that reads the XML file, I didn’t make this one. I have done a little editing.

using UnityEngine;
using System.Collections;
using System;
using System.Data;
using System.Data.Odbc;

public class textReader : MonoBehaviour {

static public string option1;
static public string option2;
static public string option3;

static public int i = 0;

// Use this for initialization
void Start () {
	readXLS(Application.dataPath + "/Book1.xls");

// Update is called once per frame
void Update () {


static public void readXLS( string filetoread)
	// Must be saved as excel 2003 workbook, not 2007, mono issue really
	string con = "Driver={Microsoft Excel Driver (*.xls)}; DriverId=790; Dbq="+filetoread+";";
	string yourQuery = "SELECT * FROM [Sheet1$]"; 
	// our odbc connector 
	OdbcConnection oCon = new OdbcConnection(con); 
	// our command object 
	OdbcCommand oCmd = new OdbcCommand(yourQuery, oCon);
	// table to hold the data 
	DataTable dtYourData = new DataTable("YourData"); 
	// open the connection 
	// lets use a datareader to fill that table! 
	OdbcDataReader rData = oCmd.ExecuteReader(); 
	// now lets blast that into the table by sheer man power! 
	// close that reader! 
	// close your connection to the spreadsheet! 
	// wow look at us go now! we are on a roll!!!!! 
	// lets now see if our table has the spreadsheet data in it, shall we? 

		// do something with the data here 
		// but how do I do this you ask??? good question! 
		// for giggles, lets see the column name then the data for that column! 
		option1 = (dtYourData.Rows[0][dtYourData.Columns*.ColumnName].ToString());* 

_ option2 = (dtYourData.Rows[1][dtYourData.Columns*.ColumnName].ToString());_
_ option3 = (dtYourData.Rows[2][dtYourData.Columns.ColumnName].ToString());*_

* }*

This is not related to XML but to XLS (Excel spreadsheet), and you’re writing about columns, but trying to iterate over rows…

In the for statement you use

but you should use

dtYourData.Rows // or maybe dtYourData.Columns - I'm not sure what you really need