Insert Data from DataTable into text file

Job ID: 32694080

Budget: $10 – $30 USD

Hello I have a simple project. I have a c# method that gets data from SQL store procedure, insert it into a text file and download it by a btn.
The issue is: the data from sql does not get inserted.
the text file and btn works fine and the method to get the data from sql also works fine.

public DataTable CreateRunOCR(int name1, int name2, int name3)
{

string sqlStatement = string.Empty;
try
{
IDBContext eddsDBContext = this.Helper.GetDBContext(workspaceArtifactID);
SqlParameter DocumentArtifactParam = new SqlParameter("@name1", workspaceArtifactID);
sqlStatement = "[EDDSDBO].[CLCS_LSA001RL_GetWRBugText]" +
" @Prod_ArtifactID = " + @name2+
" ,@Combined_SavedSearch_ArtifactID = " + @name3;
DataSet ds = eddsDBContext.ExecuteSqlStatementAsDataSet(sqlStatement, new SqlParameter[] { DocumentArtifactParam });

if (ds.Tables.Count > 0)
{
return ds.Tables[0];
}
else
{
return new DataTable();
}

}
catch (Exception ex)
{
return null;
}

Then I have a method to create text file:
public ActionResult CreateTextFile(DataTable wrInfo)
{
//DataTable dt = WrInfo.CreateRunOCR(currentWorkspaceId, Convert.ToInt32(prodData), Convert.ToInt32(savedSearchId));

var dblline = Environment.NewLine + Environment.NewLine;
var line = Environment.NewLine;

// var stagingSummaries = (List<StagingSummary>)Session["stagingSummaries"];
StringBuilder strData = new StringBuilder();

strData.Append(" " + line + " " + wrInfo + " " + dblline);

//This is for WR Number
var wrNumber = (string)Session["WRnumber"];

var byteArray = Encoding.ASCII.GetBytes(strData.ToString());
var stream = new MemoryStream(byteArray);

//Filename is wrNumber
string fName = !string.IsNullOrEmpty(wrNumber) ? wrNumber : "result";
return File(stream, "text/plain", fName + ".txt");
}
}
Then a btn to download it:
<input type="button" class="btn btn-primary" id="dwnldBtn" value="Download" />
//Download Text File
$("#dwnldBtn").click(function () {
//var link = window.location.protocol + '//' + window.location.host + "/Home/CreateTextFile?message=" + $("#txt").val();

window.open("/Relativity/CustomPages/15caf36e-d0dc-4fce-946e-55a0c0253e27/SecondPage/CreateTextFile", '_blank');

return false;
});
Related categories: .NET SQL C# Programming ASP.NET Microsoft SQL Server