我创建一个addata数据表连接数据库是成功的,现在需要用unity删除表和更新表的内容。应该是数据转换的问题。调试不成功,希望指导解决。数据表的名称为addata,有五项内容did和cid为unit类型。addx、addy、addz为float类型。
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System;
using Assets;
using MySql.Data.MySqlClient;
public class Test : MonoBehaviour
{
public float timer = 12;
//public bool OnTimer = false;
public float xx;
// Use this for initialization
public float yy;
public float zz;
private SqlAccess sqlAce;
MySqlConnection con;
void Start()
{
}
// Update is called once per frame
void Update()
{
if (Input.GetKeyDown(KeyCode.H))
{
// OnTimer = true;
StartCoroutine(Countdown());
Debug.Log("ffd");
}
//if (OnTimer == true)
//{
// }
if (Input.GetKeyDown(KeyCode.J))
{
//StopCoroutine(Countdown());
//yield return null;
// OnTimer = false;
StopAllCoroutines();
DeleteInfomation();
}
}
IEnumerator Countdown()
{
// xx = this.transform.localPosition.x;
//InsertInfomation();
UpdateInfomation();
while (true)
{
yield return new WaitForSeconds(timer);
//InsertInfomation();
UpdateInfomation();
}
}
public void DeleteInfomation()
{
//删除did为0的addx、addy、addz数据。
sqlAce = new SqlAccess();
con = SqlAccess.con;
string sql2 = string.Format("select from addata where did={0}",'0');
sqlAce.DeleteInfo(sql2, con);
}
public void UpdateInfomation()
{
//更新did为0的addx、addy、addz数据。
sqlAce = new SqlAccess();
con = SqlAccess.con;
xx = this.transform.localPosition.x;
yy = this.transform.localPosition.y;
zz = this.transform.localPosition.z;
string sql =string.Format("update addata set addx={0},addy={1},addz={2}' where did='{3}'",xx,yy,zz,0);
sqlAce.UpdateInfo(sql, con);
sqlAce.CloseMySQL();
}
}
同学你好,具体是哪部分调试不成功,是数据没有更新和删除,还是数据内容有错误,还是数据的精确度有误差呢。