示例#1
0
        public void ImportTextFileToAplication(String filePath)
        {
            gui.Rows.Clear();
            gui.ReadOnly = false;
            string[] lines  = System.IO.File.ReadAllLines(filePath);
            string[] values = new string[lines.Length];

            for (int i = 0; i < lines.Length; i++)
            {
                values = lines[i].Split(';');
                i      = gui.Rows.Add();
                for (int j = 0; j < values.Length - 1; j++)
                {
                    gui.Rows[i].Cells[j].Value = values[j].ToString();
                }
            }
            validation.AddCustomInformation();
        }
示例#2
0
        public void ImportData()
        {
            FormValidation  validation = new FormValidation(gui);
            MySqlConnection conn       = new MySqlConnection(connStr);

            try
            {
                Console.WriteLine("Connecting to MySQL...");
                conn.Open();

                string       sql  = "";
                MySqlCommand comm = new MySqlCommand();
                comm.Connection  = conn;
                comm.CommandText = "select * from laptops";
                gui.Rows.Clear();
                gui.Rows.Add();
                MySqlDataReader rdr = comm.ExecuteReader();
                int             row = 0;

                if (rdr.HasRows)
                {
                    while (rdr.Read())
                    {
                        for (int i = 0; i < rdr.FieldCount; i++)
                        {
                            for (int j = 0; j < gui.Rows[row].Cells.Count; j++)
                            {
                                int cells = gui.Rows[row].Cells.Count;
                                Console.WriteLine("Index: " + j + " " + rdr[j]);
                                gui.Rows[row].Cells[j].Value = rdr[j + 1];
                            }
                        }
                        row++;
                        gui.Rows.Add();
                    }
                }
                validation.AddCustomInformation();
                conn.Close();
            }
            catch (MySqlException mysql)
            {
                Console.Error.WriteLine(mysql.Message);
            }

            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
            }


            Console.WriteLine("Done.");
        }