public ActionResult ConvertToTextfile() { string mySQL; DataTable table = new DataTable(); DataSet myDataSet = new DataSet(); mySQL = "Select * From MOUVEMSSE.Mouvem11 "; string connect = System.Configuration.ConfigurationManager.AppSettings["dsn_AS400"]; string conn_string = connect + "UID=" + HttpContext.Session["Username"] + ";PWD=" + HttpContext.Session["Password"] + ";"; db_tools.sg_connStr = conn_string; connection = db_tools.Connect(); table = db_tools.ExecuteSelectCommand(mySQL, CommandType.Text); myDataSet.Tables.Add(); string folderLocation = @"C:\Users\zarai\source\repos\Sms_Chauffeur\Sms_Chauffeur\Extractedfiles"; // your path to save the files for (int i = 0; i<table.Rows.Count; i++) // iterate each rows to get the value { string fileName = folderLocation + "\\" + "File-" + i + ".txt"; // file name for saving each row string contents = ""; foreach (DataColumn col in table.Columns) // iteate each column to get its corresponding value contents += table.Rows[i][col].ToString() + " "; // concatenating the contents System.IO.File.WriteAllText(fileName, contents); // create a text file and copy the contents } return View("data Extracted sucssessfuly"); }
<pre> <table id="example" class="display" style="width:100%"> <thead> <tr> <!-- <th>-</th>--> <th>DATE</th> <th>ORDBUS</th> <th>ORDSER</th> <th>SEQUEN</th> <th>HEUDEB</th> <th>HEUFIN</th> <th>Actions</th> </tr> </thead> <tbody> @foreach (DataRow row in Model.Tables[0].Rows) { <tr class="active-row"> <!-- <td><input type="checkbox" /> </td>--> <td>@row["DATMVT"]</td> <td>@row["ORDBUS"]</td> <td>@row["ORDSER"]</td> <td>@row["SEQUEN"]</td> <td>@row["HEUDEB"]</td> <td>@row["HEUFIN"]</td> <td> <button type="submit" class="btn btn-primary" value=Edit>EDIT</button> </td> </tr> } </tbody> </table>
@using (Html.BeginForm("ConvertToTextfile", "Display", FormMethod.Get)) { <input type="submit" value="Submit" /> }
DataTable
ActionResult
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)