Get data from txt file and update db RRS feed

  • Question

  • User-227441786 posted

    I have txt file ,, in which student  fee status is entered.. like (submitted)

    and i 've table in my sql where it status is pending

    How i can get data from txt file and update my sql record according to txt file..

    any help

    Wednesday, December 4, 2013 10:22 AM


  • User1508394307 posted

    Your question does not provide all details. There is a number of options you can use, starting from export file directly to your database (using Import/Export Wizard) to something like the example below.

    using(SqlConnection con = new SqlConnection("Data Source=...;Initial Catalog=...;Integrated Security=SSPI"))
       // define the SQL insert statement and use parameters
       string sqlStatement = "UPDATE dbo.YourTable SET status='xxx' WHERE student=@student";
       // define the SqlCommmand to do the insert - use the using() approach again  
       using(SqlCommand cmd = new SqlCommand(sqlStatement, con))
    	string importfile = Server.MapPath("~/app_data/textfile.txt"); // if file is located at the app_data 
    	// read the lines from the text file
    	string[] allLines = File.ReadAllLines(importfile);
    	// start counting from index = 1 if file include some header row
    	for (int index = 0; index < allLines.Length; index++)
    		// for example if file incldes only names
    		string student = allLines[index]; 
    		cmd.Parameters["@student"].Value = student; 

    Hope this helps.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, December 4, 2013 11:32 AM