c# - How can I read remote sql tables into a winforms program? -


i have sql server table located on website (remote). table called table1 , contains bunch of fields. goal here read fields of table1 array called results.

here attempt:

 private static void showfields()         {             using (sqlconnection connection = new sqlconnection(connectionstring))             {                 connection.open();                  sqlcommand command = new sqlcommand("select * information_schema.columns table_name='table1'", connection);                  string[] results = command.beginexecutenonquery().toarray();                  connection.close();                   foreach (var v in results)                 {                     console.writeline(v);                  }             }         } 

you need use sqlcoomand.executereader() instead of:

 private static void showfields()  {      using (sqlconnection connection = new sqlconnection(connectionstring))      {          connection.open();           sqlcommand command = new sqlcommand("select * information_schema.columns table_name='table1'", connection);          sqldatareader reader = command.executereader();           connection.close();           int colcount = reader.fieldcount;           while (reader.read())          {              (int = 0; < colcount; i++)              {                  console.writeline(reader.getstring(i));              }          }      }  } 

Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

javascript - jQuery .height() return 0 when visible but non-0 when hidden -