In this article i have read the data from csv file using c# .
using (var reader = new StreamReader(@"C:\brij2019\sample question data\sample questions.csv"))
{
int c = 0;
string tempOp = "";
string tempQ = "";
string tempQBody = "";
while (!reader.EndOfStream)
{
var line = reader.ReadLine();
//Response.Write(" <br>"+line+"<br> ");
var values = line.Split(',');
// Response.Write(" <br>" + values[0] + "<br> ");
if (values[0] != "")
{
if (c > 0)
{
// Response.Write("<br>" + tempQ + " " + tempOp + " " + tempQBody);
if (insertSurveyQuestionToDatabase(tempQ, tempOp, tempQBody))
{
Response.Write("<br> Question Imported for q Code = "+tempQ);
}
}
tempQ = values[0];
tempQBody = values[1];
// Response.Write("<br>" + tempQ + " " + tempOp + " " + tempQBody);
tempOp = "";
c++;
}
else
{
if (tempOp == "")
{
tempOp += values[2];
}
else
{
tempOp += "," + values[2];
}
}
using (var reader = new StreamReader(@"C:\brij2019\sample question data\sample questions.csv"))
{
int c = 0;
string tempOp = "";
string tempQ = "";
string tempQBody = "";
while (!reader.EndOfStream)
{
var line = reader.ReadLine();
//Response.Write(" <br>"+line+"<br> ");
var values = line.Split(',');
// Response.Write(" <br>" + values[0] + "<br> ");
if (values[0] != "")
{
if (c > 0)
{
// Response.Write("<br>" + tempQ + " " + tempOp + " " + tempQBody);
if (insertSurveyQuestionToDatabase(tempQ, tempOp, tempQBody))
{
Response.Write("<br> Question Imported for q Code = "+tempQ);
}
}
tempQ = values[0];
tempQBody = values[1];
// Response.Write("<br>" + tempQ + " " + tempOp + " " + tempQBody);
tempOp = "";
c++;
}
else
{
if (tempOp == "")
{
tempOp += values[2];
}
else
{
tempOp += "," + values[2];
}
}