i am beginer to unity . i using single table to keep data as player name , password , id, i can able to reed from table when it valuse or given at default, bur the problem is i cant able to insrt the data in runtime to Ms access…
can some one pl help me…
my code is below
import UnityEngine;
import System.Collections;
import System;
import System.Data;
import System.Data.Odbc;
import UnityEditor;
var ex;
var i;
//throw new Error();
var display;
private var wim_rect = Rect(80,20,400,400);
public var p_id = “”;
public var p_pass = “”;
public var p_name = “”;
function OnGUI ()
{
GUI.color=Color.yellow;
wim_rect= GUI.Window(0,wim_rect,do_win," MENU ");
}
function do_win(windowId : int)
{
GUI.Label(Rect(105,100,300,30), " Enter The Detials Below Proced ");
GUI.Label(Rect(50,200,140,30), " Enter Your ID : ");
p_id = GUI.TextArea(Rect(200,200,120,30),p_id,6);
GUI.Label(Rect(50,250,140,30), " Enter Your Name : “);
p_name = GUI.TextArea(Rect(200,250,120,30),p_name,6);
GUI.Label(Rect(50,300,140,30), " Enter Password : “);
p_pass = GUI.PasswordField(Rect(200,300,120,30),p_pass,”$”[0],6);
/*if(p_id.Length < 6 p_name.Length < 6 p_pass.Length < 6 )
{
var display=1;
//GUI.Label(Rect(375,250,300,30), " Enter All Detials Proced ");
EditorUtility.DisplayDialog(“Game Object Facts”,“ok”, “cancel”);
}
else
display=2;
*/
// if((GUI.Button(Rect(125,375,50,20), " OK ")) (display == 2))
if(GUI.Button(Rect(125,375,50,20), " OK “))
{
Application.LoadLevel(“second”);
//EditorUtility.DisplayDialog(“Game Object Facts”,“ok”, “cancel”);
gameObject.SendMessage(“up_date”);
}
if(GUI.Button(Rect(215,375,60,20), " Cancel “))
{
Destroy(gameObject);
//SendMessage(” you on quit button”,SendMessageOptions.RequireReceiver);
}
}
private var read;
private var con;
private var yourQuery;
private var oCon : OdbcConnection;
private var oCmd : OdbcCommand;
private var dtYourData : DataTable;
private var rData : OdbcDataReader;
function up_date()
{
var read= Application.dataPath + “/Database1.mdb”;
var con = “Driver={Microsoft Access Driver (*.mdb)}; DBQ=”+read;
Debug.Log(con);
var yourQuery = " INSERT INTO Players (ID, Name, Password) " + " VALUES ( p_id , p_name , p_pass );";
// our odbc connector
var oCon : OdbcConnection = new OdbcConnection(con);
// our command object
var oCmd : OdbcCommand = new OdbcCommand(yourQuery, oCon);
// table to hold the data
var dtYourData : DataTable = new DataTable(“YourData”);
try
{
// open the connection
oCon.Open();
// lets use a datareader to fill that table!
var rData : OdbcDataReader = oCmd.ExecuteReader();
// now lets blast that into the table by sheer man power!
dtYourData.Load(rData);
// close that reader!
rData.Close();
// close your connection to the spreadsheet!
oCon.Close();
// 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?
}
catch (Ex )
{
Debug.Log(Ex);
}
finally
{
if (oCon.State != ConnectionState.Closed)
oCon.Close();
oCon.Dispose();
}
/if(dtYourData.Rows.Count > 0)
{
// do something with the data here
// but how do I do this you ask??? good question!
for (i = 0; i < dtYourData.Rows.Count; i++)
{
// for giggles, lets see the column name then the data for that column!
Debug.Log(dtYourData.Columns[0].ColumnName + " : " + dtYourData.Rows[dtYourData.Columns[0].ColumnName].ToString() +*
_ " | " + dtYourData.Columns[1].ColumnName + " : " + dtYourData.Rows*[dtYourData.Columns[1].ColumnName].ToString() +_
_ " | " + dtYourData.Columns[2].ColumnName + " : " + dtYourData.Rows[dtYourData.Columns[2].ColumnName].ToString());*_
_ var id = dtYourData.Rows*[dtYourData.Columns[0].ColumnName].ToString();
var nam = dtYourData.Rows[dtYourData.Columns[1].ColumnName].ToString();
var pass = dtYourData.Rows[dtYourData.Columns[2].ColumnName].ToString();*_
* }*
* }*
_ /
}
********************
some one pls help_