Search Unity

how to retrive the the data from Ms access from unity

Discussion in 'General Discussion' started by Arun_Rajps, Sep 3, 2010.

  1. Arun_Rajps

    Arun_Rajps

    Joined:
    Aug 25, 2010
    Posts:
    68
    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
     
  2. zumwalt

    zumwalt

    Joined:
    Apr 18, 2007
    Posts:
    2,287
    As I stated in the following thread:
    http://forum.unity3d.com/viewtopic.php?t=62061&start=15

    There is a BUG in Unity, thus, Insert/Update/Delete to Access will NOT WORK until the bug is fixed, and I did file a bug report back when I discovered it, so no one can help until the bug is fixed. You can however, file your own bug report attaching your project to it so that they have more information to go on and test with. It is still a bug as of U3B7, so no, it is not fixed yet.
     
  3. tabtabai

    tabtabai

    Joined:
    Sep 24, 2014
    Posts:
    1
    I'm interested in this as well, I tried to click the link provided by zumwalt but it didn't take me anywhere. Any solution or tutorial out there for accessing Microsoft Access DB ?
     
  4. Ryiah

    Ryiah

    Joined:
    Oct 11, 2012
    Posts:
    21,205
    His link is over four years old. I would try it and see if they have fixed it by now. He was having problems with Unity 3 Beta and we're a lot farther along than that now.
     
  5. JamesLeeNZ

    JamesLeeNZ

    Joined:
    Nov 15, 2011
    Posts:
    5,616
    *shudder* access