Из массива создать бд в SQL
как сделать так чтобы при выполнении команд CREATE создавалась база не в txt а в sql а при командах LOAD вся таблица из MySQL переносится в массив, а при SAVE - сохраняется в таблицу
string run_cmd(string cmd)
{
char[] sep = new char[] { ' ' };
string[] arr = cmd.Split(sep, StringSplitOptions.RemoveEmptyEntries);
if (arr.Length < 1) return "";
string res = "";
switch (arr[0].ToUpper())
{
case "LOAD":
if (arr.Length != 2) res = "ERR invalid number of arguments";
else
{
string[] ln = null;
try
{
ln = File.ReadAllLines(arr[1] + ".txt");
}
catch (Exception ex)
{
res = "ERR failed to load";
break;
}
int i = find_ds(arr[1]);
if (i < 0)
{
dataset x;
x.name = arr[1];
x.smp = new List<sample>();
ds.Add(x);
i = ds.Count - 1;
}
else ds[i].smp.Clear();
for (int j = 0; j < ln.Length; j++)
{
String[] fld = ln[j].Split('\t');
sample x;
x.time = int.Parse(fld[0]);
x.value = float.Parse(fld[1]);
ds[i].smp.Add(x);
}
res = "OK file loaded";
}
break;
case "SAVE":
if (arr.Length != 2) res = "ERR invalid number of arg";
else
{
int i = find_ds(arr[1]);
if (i < 0) res = "ERR dataset not found";
else
{
string txt = "";
for (int j = 0; j < ds[i].smp.Count; j++)
txt = txt + ds[i].smp[j].time.ToString() + "\t" + ds[i].smp[j].value.ToString() + Environment.NewLine;
File.WriteAllText(arr[1] + ".txt", txt);
res = "OK file saved";
}
}
break;
case "CREATE":
if (arr.Length != 2) res = "ERR invalid number of arg";
else
{
int i = find_ds(arr[1]);
if (i < 0)
{
dataset x;
x.name = arr[1];
x.smp = new List<sample>();
ds.Add(x);
res = "OK created new dataset ";
}
else res = "ERR dataset already exist ";
}
break;