namespace ConsoleApplication2 { class Program { string path = @"text file path"; SqlConnection con = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["constring"].ToString()); public void getConsoleInput() { try { FileInfo fi = new FileInfo(path); for (int i = 0; i <= 0; i++) { Console.WriteLine(""); using (StreamWriter sw = new StreamWriter(path)) { sw.WriteLine(Console.ReadLine()); sw.Close(); } } } catch (Exception e) { Console.WriteLine(e.Message); } } public void ReadWriteIntoFile() { try { string filename = @"txt file path"; StringBuilder sb = new StringBuilder(); StreamReader sr = new StreamReader(path); string s = sr.ReadLine(); sr.Close(); DataExport("Select * from PATIENT_TABLE where [BARCODE] = '" + s + "'", filename); } catch { } } public void DataExport(string SelectQuery, string filename) { try { using (var dt = new DataTable()) { using (var da = new SqlDataAdapter(SelectQuery, con)) { da.Fill(dt); var rows = from dr in dt.Rows.Cast<datarow>() select String.Join( ",", from dc in dt.Columns.Cast<datacolumn>() let t1 = Convert.IsDBNull(dr[dc]) ? "" : dr[dc].ToString() let t2 = t1.Contains(",") ? String.Format("\"{0}\"", t1) : t1 select t2); using (var sw = new StreamWriter(filename)) { // sw.WriteLine(header); foreach (var row in rows) { sw.WriteLine(row); } sw.Close(); } } } } catch (Exception e) { Console.WriteLine(e.Message); } } public void WriteFileOutput() { string path = @"text file path"; if (File.Exists(path)) { string[] lines = File.ReadAllLines(path); foreach (string line in lines) { Console.WriteLine(line); } } Console.ReadLine(); } public static void Main(string[] args) { Program p = new Program(); p.getConsoleInput(); p.ReadWriteIntoFile(); p.WriteFileOutput(); } public void timerfor() { Timer t; t = new System.Timers.Timer(10000); // Hook up the Elapsed event for the timer. t.Elapsed += OnTimedEvent; t.Enabled = true; } private static void OnTimedEvent(Object source, ElapsedEventArgs e) { Console.WriteLine(ConsoleKey.Enter); } } } <pre lang="c#">
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)