而如果想要查看该数据库中的另一个表,不是直接使用table[1],而是需要更改select * from <?>的表名
代码:
using system.collections;
using system.collections.generic;
using unityengine;
using mysql.data.mysqlclient;
using system.data;
using system;
public class getgameuseraccount : monobehaviour
{
// start is called before the first frame update
void start()
{
mysqlcon();
}
// update is called once per frame
void update()
{
}
public void mysqlcon()
{
//数据库登录数据
string constr = "server=localhost;user id = root;password=123456;database=gamerdata;charset=utf8";
//建立连接
//实例化的同时调用mysqlconnection,传入参数
//这里的传入参数个人认为是cmd里面的直接输入了,string格式直接类似手敲到cmd里面
mysqlconnection mycon = new mysqlconnection(constr);
//打开连接
mycon.open();
//插入数据,其中useraccount为表名,括号内为表的格式
/*
//此处注释是因为不能添加相同主键的值
mysqlcommand mycmd = new mysqlcommand("insert into useraccount(id,nickname,password) values (4,'list','testlist')", mycon);
if (mycmd.executenonquery() > 0)
{
debug.log("query success!");
}
*/
//查询数据
string selstr = "select * from useraccount";
mysqlcommand myselect = new mysqlcommand(selstr, mycon);
dataset ds = new dataset();
try
{
mysqldataadapter da = new mysqldataadapter(selstr, mycon);
da.fill(ds);
debug.log(ds.tables[0].rows[0][0]);
debug.log(ds.tables[0].rows[0][1]);
debug.log(ds.tables[0].rows[0][2]);
debug.log(ds.tables[0].rows[0][3]);
//table[0].rows[0][0]
debug.log("query success!");
}
catch (exception e)
{
throw new exception("sql:" + selstr + "\n" + e.message.tostring());
}
mycon.close();
}
}