大致写写思路,因为sqlserver提供了可以直接导入的图形界面。
1、private static string GetConnectionString(string folderPath) //文件夹路径
{
string [email protected]"Provider=Microsoft.Jet.OLEDB.4.0;Data Source="[email protected]"\;Extended Properties=‘Text;‘";
return connectionString;
}
2、string sql="select from 1.csv";
DataTable dt=OleDbHelper.Query(@"C:\Users\Administrator\Desktop",sql);
StringBuilder sb=new StringBuilder();
string portCode=string.Empty;
string nameCode=string.Empty;
if(dt!=null&&dt.Rows.Count>0)
{
foreach(DataRow dr in dt.Rows)
{
portCode=dr["portCode"].ToString();
nameCode=dr["nameCode"].ToString();
sb.AppendLine("insert into TableName (portCode,nameCode) values(‘"+portCode+"‘,‘"+nameCode+"‘)");
}
string result=sb.ToString();
}
DbHelper.ExecuteSql(result);