Greetings all
This is my 1st post as I am a very new Unity user.
I am trying to get some records from an SQL database and display them in a GUI box. I have been using code found on the forums here but so far no good.
I have imported system.data.dll (.net version 2) into my assets folder and used the following script:
using UnityEngine;
using System.Collections;
using System;
using System.Data;
using System.Data.SqlClient;
class DataAccess : MonoBehaviour
{
public string result;
//This is your database connection:
static string connectionString = ādata source=c101841-svr;initial catalog=AssetDatabase;uid=jallan;pwd=blah;ā;
static SqlConnection cn = new SqlConnection(connectionString);
// This is your command to execute:
static string sCommand = āSELECT * FROM dbo.Assetsā;
// This is your data adapter that understands SQL databases:
static SqlDataAdapter da = new SqlDataAdapter(sCommand, cn);
// This is your table to hold the result set:
static DataTable dataTable = new DataTable();
void Start()
{
cn.Open();
// Fill the data table with select statementās query results:
int recordsAffected = da.Fill(dataTable);
if (recordsAffected > 0)
{
foreach (DataRow dr in dataTable.Rows)
{
result = dr[āSerialNumberā].ToString();
}
}
}
// void OnGUI()
// {
// GUI.Label (new Rect (10, 10, 200, 20), "Username from database: "+result);
// }
}
I then dragged that script on to the 3rd person controller to activate it and I get the following error in my console:
InvalidProgramException: Invalid IL code in :.cctor (): IL_0032: call 0x0a00000a
If anyone can help I would be very grateful. If anyone has a step by step guide to getting this kind of thing working that would be even better
Thanks in advance.
James