Last post Dec 04, 2013 11:32 AM by smirnov
Dec 04, 2013 10:22 AM|NafeesAbbasi|LINK
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..
Dec 04, 2013 11:32 AM|smirnov|LINK
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.