예제 #1
0
    public static int Query_One_Record(MySqlConnection com, string table, int num, ref Test_Questions data)
    {
        string query_str = "select ID, Subject, A, B, C, Answer from " + table + " where ID = " + num.ToString();

        try
        {
            MySqlCommand    myCmd  = new MySqlCommand(query_str, com);
            MySqlDataReader reader = myCmd.ExecuteReader();
            if (reader.Read() == true)
            {
                data.Title_Number = reader.GetInt32(0);
                data.Subject      = reader.GetString(1);
                data.Option_A     = reader.GetString(2);
                data.Option_B     = reader.GetString(3);
                data.Option_C     = reader.GetString(4);
                data.Answer       = reader.GetString(5);
            }
            else
            {
                Console.WriteLine("没有查询到些ID的数据:{0}!", num);
                return(-1);
            }
            reader.Close();
            //Console.WriteLine("表不存在");
            return(0x00);
        }
        catch (Exception ex)
        {
            Console.WriteLine("查询库中的表错误:{0}!", ex.ToString());
            return(-1);
        }
    }
예제 #2
0
    private void Start()
    {
        TQ = FindObjectOfType <Test_Questions>();
        TA = FindObjectOfType <Test_Answers>();

        PL = FindObjectOfType <Player_Life>();

        cs = FindObjectOfType <cannon_shoot>();

        RI = FindObjectOfType <RandomIndex>();
    }
예제 #3
0
    //插入一行数据
    //返回值:0x00>插入成功 -1>插入失败
    public static int Insert_Table(MySqlConnection con, string table, Test_Questions data)
    {
//            string insert_str = "INSERT INTO " + table + " VALUES ( "+ "\"" + data.Subject + "\""+", " + "\""+ data.Option_A + "\""+ ", " + "\""+ data.Option_B + "\""+ ", " + "\""+ data.Option_C + "\""+ ", " + "\""+ data.Answer + "\""+ " );";
        string insert_str = "INSERT INTO " + table + "(Subject, A, B, C, Answer)" + " VALUES ( " + "\"" + data.Subject + "\"" + ", " + "\"" + data.Option_A + "\"" + ", " + "\"" + data.Option_B + "\"" + ", " + "\"" + data.Option_C + "\"" + ", " + "\"" + data.Answer + "\"" + " );";

        Console.WriteLine("INSERT = {0}", insert_str);

        try
        {
            MySqlCommand cmd = new MySqlCommand(insert_str, con);
            cmd.ExecuteNonQuery();
            return(0x00);
        }
        catch (Exception ex)
        {
            Console.WriteLine("插入数据失败!{0}", ex.ToString());
            return(-1);
        }
    }