我有一个从CSV文件创建SQL数据库的函数。但是当它用变音符号读取一个字符时,它会在我的SQL表中显示一个问号。我怎样才能解决这个问题?这是我的代码:
private static System.Data.DataTable GetDataTabletFromCSVFile(string csv_file_path, string tablenaam)
{
System.Data.DataTable csvData = new System.Data.DataTable();
try
{
using (TextFieldParser csvReader = new TextFieldParser(csv_file_path))
{
csvReader.SetDelimiters(new string[] { "," });
csvReader.HasFieldsEnclosedInQuotes = true;
string[] colFields = csvReader.ReadFields();
foreach (string column in colFields)
{
DataColumn datecolumn = new DataColumn(column);
datecolumn.AllowDBNull = true;
csvData.Columns.Add(datecolumn);
}
while (!csvReader.EndOfData)
{
string[] fieldData = csvReader.ReadFields();
//Making empty value as null
for (int i = 0; i < fieldData.Length; i++)
{
if (fieldData[i] == "")
{
fieldData[i] = null;
}
}
csvData.Rows.Add(fieldData);
}
}
}
catch (Exception ex)
{
}
InsertDataIntoSQLServerUsingSQLBulkCopy(csvData,tablenaam);
return csvData;
}
答案 0 :(得分:1)