CSV を SQL サーバーにエクスポートする作業を行っていますが、何もエクスポートされません。私は次のコードを持っています:
protected void uploadButton_Click(object sender, EventArgs e)
{
DataTable tblReadCSV = new DataTable();
tblReadCSV.Columns.Add("IP");
tblReadCSV.Columns.Add("activityStart");
tblReadCSV.Columns.Add("activityEnd");
tblReadCSV.Columns.Add("RCPTcommands");
tblReadCSV.Columns.Add("DataCommands");
tblReadCSV.Columns.Add("MessageRecipients");
tblReadCSV.Columns.Add("FilterResultColor");
tblReadCSV.Columns.Add("complaintRate");
tblReadCSV.Columns.Add("trapStart");
tblReadCSV.Columns.Add("trapEnd");
tblReadCSV.Columns.Add("trapHits");
tblReadCSV.Columns.Add("sampleHelo");
tblReadCSV.Columns.Add("sampleMailFrom");
tblReadCSV.Columns.Add("comments");
tblReadCSV.Columns.Add("URL");
string path = System.IO.Path.GetFileName(FileUpload1.PostedFile.FileName);
FileUpload1.PostedFile.SaveAs(Server.MapPath("~/UploadFiles/" + path));
path = Server.MapPath("~/UploadFiles/" + path);
TextFieldParser csvParser = new TextFieldParser(path);
csvParser.Delimiters = new string[] { "," };
csvParser.TrimWhiteSpace = true;
csvParser.ReadLine();
while (!(csvParser.EndOfData == true))
{
tblReadCSV.Rows.Add(csvParser.ReadFields());
}
string strCon = ConfigurationManager.ConnectionStrings["conMailMonitor"].ConnectionString;
string strSql = "INSERT INTO tblSnds(IP,activityStart,activityEnd,RCPTcommands,DataCommands,MessageRecipients,FilterResultColor,complaintRate,trapStart,trapEnd,trapHits,sampleHelo,sampleMailFrom,comments,URL)VALUES(@IP,@activityStart,@activityEnd,@RCPTcommands,@DataCommands,@MessageRecipients,@FilterResultColor,@complaintRate,@trapStart,@trapEnd,@trapHits,@sampleHelo,@sampleMailFrom,@comments,@URL)";
SqlConnection con = new SqlConnection(strCon);
SqlCommand cmd = new SqlCommand();
cmd.CommandType = CommandType.Text;
cmd.CommandText = strSql;
cmd.Connection = con;
cmd.Parameters.Add("@IP", SqlDbType.VarChar, 50, "IP");
cmd.Parameters.Add("@activityStart", SqlDbType.VarChar, 50, "activityStart");
cmd.Parameters.Add("@activityEnd", SqlDbType.VarChar, 50, "activityEnd");
cmd.Parameters.Add("@RCPTcommands", SqlDbType.VarChar, 50, "RCPTcommands");
cmd.Parameters.Add("@DataCommands", SqlDbType.VarChar, 50, "DataCommands");
cmd.Parameters.Add("@MessageRecipients", SqlDbType.VarChar, 50, "MessageRecipients");
cmd.Parameters.Add("@FilterResultColor", SqlDbType.VarChar, 50, "FilterResultColor");
cmd.Parameters.Add("@complaintRate", SqlDbType.VarChar, 50, "complaintRate");
cmd.Parameters.Add("@trapStart", SqlDbType.VarChar, 50, "trapStart");
cmd.Parameters.Add("@trapEnd", SqlDbType.VarChar, 50, "trapEnd");
cmd.Parameters.Add("@trapHits", SqlDbType.VarChar, 50, "trapHits");
cmd.Parameters.Add("@sampleHelo", SqlDbType.VarChar, 50, "activityEnd");
cmd.Parameters.Add("@sampleMailFrom", SqlDbType.VarChar, 50, "sampleMailFrom");
cmd.Parameters.Add("@comments", SqlDbType.VarChar, 50, "comments");
cmd.Parameters.Add("@URL", SqlDbType.VarChar, 50, "URL");
SqlDataAdapter dAdapter = new SqlDataAdapter();
dAdapter.InsertCommand = cmd;
int result = dAdapter.Update(tblReadCSV);
Label1.Text = "File successfully uploaded";
}
CSV の内容は次のとおりです。
216.211.128.7,8/12/2013 8:00 AM,8/13/2013 8:00 AM,6610,5642,5644,GREEN,< 0.1%,8/12/2013 11:23 AM,8/12/2013 11:36 AM,4,mail2.adhost.com,bpsupport@betterphoto.com,
デバッグすると、制御が while ループ内に入らないことがわかります
while (!(csvParser.EndOfData == true))
それを行う方法を提案してください?