none
I want to draw sql query from txt file RRS feed

  • Question

  • Hello,
    I'm using Visual Studio 2015. "C: \ sqlquery.txt" file has 100 lines of a SQL query. Will read this file and looking for a sample code to send SQL queries.,

    using System.IO;
    SqlConnection bag = new SqlConnection(@"Data Source=ADMIN;Initial Catalog=2015;User ID=data1;Password=****; );
     string sorgu;
     bag.Open();
    sorgu = ".....
    ....
    ....
    ...
    ....
    ....
    ...
    ";
    SqlDataAdapter sqlAdp = new SqlDataAdapter(sorgu, bag);
                    DataTable dt = new DataTable();
                    dataGridView1.DataSource = dt;
                    sqlAdp.Fill(dt);


    How a loop, c: \ sqlquery.txt file the lines can send SQL queries to read?

    • Moved by lake Xiao Monday, March 7, 2016 6:00 AM
    Friday, March 4, 2016 10:48 PM

Answers

  • All Codes

     SqlConnection bag = new SqlConnection(@"Data Source=****;Initial Catalog=****;User ID=***;Password=**");               

    string sorgu;               

    bag.Open();               

    sorgu = File.ReadAllText("c:\\ sqlquery.txt");

    SqlDataAdapter sqlAdp = new SqlDataAdapter(sorgu, bag);

    DataTable dt = new DataTable();

    dataGridView1.DataSource = dt;

    sqlAdp.Fill(dt);




    Monday, March 7, 2016 8:26 AM

All replies

  • Hi RahirSalt,

    Could you please tell me what's the content in your txt file? And if possible, please provide some more detailed information about your requirement?

    In addition, since our forum is discussing about Unit Test. And It seems like your problem is related to the Data Connection. I moved your thread to the corresponding forum for better support.

    Thanks for your understanding.

    Best Regards,

    Lake Xiao

    Monday, March 7, 2016 5:59 AM
  • Thank you for your attention. I found the answer to my question

    sorgu = File.ReadAllText("c:\\ sqlquery.txt");
    Monday, March 7, 2016 8:22 AM
  • All Codes

     SqlConnection bag = new SqlConnection(@"Data Source=****;Initial Catalog=****;User ID=***;Password=**");               

    string sorgu;               

    bag.Open();               

    sorgu = File.ReadAllText("c:\\ sqlquery.txt");

    SqlDataAdapter sqlAdp = new SqlDataAdapter(sorgu, bag);

    DataTable dt = new DataTable();

    dataGridView1.DataSource = dt;

    sqlAdp.Fill(dt);




    Monday, March 7, 2016 8:26 AM