Untitled

 avatar
unknown
csharp
3 years ago
1.6 kB
30
Indexable
        public static string GetData(string _table, string _string, string _where, string _is)
        {
            // Column specification
            int i = 0;
            if (_string == "production_line")
                i = 1;
            if (_string == "type")
                i = 2;
            if (_string == "note")
                i = 3;
            if (_string == "calculation1")
                i = 4;
            if (_string == "calculation2")
                i = 5;
            if (_string == "calculation3")
                i = 6;
            if (_string == "picture")
                i = 7;
            if (_string == "error_en")
                i = 8;
            if (_string == "error_cz")
                i = 9;
            if (_string == "service_information")
                i = 10;

            string temp = "";
            string query = $@"SELECT * FROM {_table} WHERE {_where}={_is};";
            OdbcCommand cmd = new OdbcCommand(query, connect());

            if (connected == true)
            {
                try
                {
                    OdbcDataReader reader = cmd.ExecuteReader();
                    while (reader.Read())
                    {
                        temp = reader.GetString(i);
                        Disconnect();
                        return temp;
                    }
                    return "-";
                }
                catch (OdbcException ex)
                {
                    Error = ex.Message;
                }
            }
            return "-";
        }