第一次运行,当没有WinRemoteDesktop.db时,新建远程会如下错误:
![输入图片说明](https://images.gitee.com/uploads/images/2020/1020/112847_f118cdfb_1716151.png "屏幕截图.png")
我对TXTClass().txtRead(string filepath, char split)方法进行了代码进行了优化:
```
///
/// 读取txt文件内容,读取结果以DataTable(列名分别为c0,c1,c2,c3,... ...)形式返回
///
/// txt文件每一行中不同列之间的分隔符
///
public DataTable txtRead(string filepath, char split)
{
DataTable table = new DataTable();
try
{
string str2;
this.FileNotExistAndCreate(filepath);
FileStream stream = new FileStream(filepath, FileMode.Open, FileAccess.Read);
StreamReader reader = new StreamReader(stream);
reader.BaseStream.Seek(0L, SeekOrigin.Begin);
string str = reader.ReadLine();
if (!String.IsNullOrWhiteSpace(str))
{
int length = str.Split(new char[] { split }).Length;
for (int i = 0; i < length; i++)
{
str2 = "c" + i.ToString();
table.Columns.Add(str2, typeof(string));
}
while ((str != null) && (str != ""))
{
string[] strArray2 = str.Split(new char[] { split });
DataRow row = table.NewRow();
for (int j = 0; j < length; j++)
{
str2 = "c" + j.ToString();
row[str2] = strArray2[j];
}
table.Rows.Add(row);
table.AcceptChanges();
str = reader.ReadLine();
}
}
reader.Close();
stream.Close();
}
catch (Exception exception)
{
string text = exception.ToString();
if (exception.InnerException != null)
{
text = text + exception.InnerException.ToString();
}
if (exception.StackTrace != null)
{
text = text + exception.StackTrace.ToString();
}
MessageBox.Show(text);
}
return table;
}
```