导入csv后,问号存储在数据库中 [英] Question mark is storing in database after importing csv
本文介绍了导入csv后,问号存储在数据库中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我已成功将CSV导入到c#windows窗体中的sql.But导入后,
当我检查数据库中的表格给select *时,我观察到,在表格的许多字段中插入了不必要的问号。
Plz帮助
Hi,
I have successfully imported CSV to sql in c# windows forms.But after Importing,
When I check the table in database giving select *, I observed, there are unneccessary question marks inserted in many fields of the table.
Plz help
private DataTable GeTDataTable(string fName)
{
DataTable dt = new DataTable();
dt.Columns.Add("supplier",typeof(string));
dt.Columns.Add("AlternateSupplier",typeof(string));
dt.Columns.Add("VendorNumber",typeof(string));
dt.Columns.Add("NapaNetId",typeof(string));
dt.Columns.Add("PayTerms",typeof(string));
dt.Columns.Add("VendorEmailId",typeof(string));
dt.Columns.Add("FileFormat",typeof(string));
dt.Columns.Add("LinesPerStat",typeof(string));
dt.Columns.Add("NumStat_Loc",typeof(string));
dt.Columns.Add("AutoZero",typeof(Int32));
dt.Columns.Add("No_Lead_zero", typeof(Int32));
dt.Columns.Add("Lead_Alpha", typeof(Int32));
dt.Columns.Add("splInstruction",typeof(string));
dt.Columns.Add("VendorPhoneNo",typeof(string));
dt.Columns.Add("AccountNumber",typeof(string));
Boolean First = true ;
TextFieldParser sw = new TextFieldParser(fName);
sw.Delimiters = new string[] { "," };
sw.HasFieldsEnclosedInQuotes = true;
while (!sw.EndOfData)
{
string[] Val = sw.ReadFields();
if (First == true)
{
First = false; continue;
}
for (int i = 0; i < Val.Length; i++)
{
Val[i] = Val[i].Replace(",", " ");
}
DataRow dr = dt.NewRow();
dr[0] = Val[0];
dr[1] = Val[1];
dr[2] = Val[2];
dr[3] = Val[3];
dr[4] = Val[4];
dr[5] = Val[5];
dr[6] = Val[6];
dr[7] = Val[7];
dr[8] = (string.IsNullOrEmpty(Val[8])==true || Val[9].ToString() =="X")? "F":"S";
dr[9] = string.IsNullOrEmpty(Val[9]) == true ? 0 : 1;
dr[10] = string.IsNullOrEmpty(Val[10]) == true ? 0 : 1;
dr[11] = string.IsNullOrEmpty(Val[11]) == true ? 0 : 1;
dr[12] = Val[12];
dr[13] = Val[13];
dr[14] = string.IsNullOrEmpty(Val[14]) == true ? string.Empty : Val[14].ToString().Trim() ;
dt.Rows.Add(dr);
}
return dt;
//sw.Close();
}
}
}
推荐答案
这是以非UTF-8格式(如ANSI)保存文件的结果。当您使用不支持UTF-8的文本编辑器打开文件并再次保存时,会发生这种情况。
参考:
Link1 [ ^ ]
Link2 [ ^ ]
This is the result of saving your files in non UTF-8 format such as ANSI. When you open a file with text editors that don''t support UTF-8 and save it again, this will happen.
Refer:
Link1[^]
Link2[^]
这篇关于导入csv后,问号存储在数据库中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文