c# - How do I get sqldatareader to show the data in the fields? -
i have sql server table located on website (remote). table called table1
, contains bunch of fields. goal here read fields of table1
array iterate.
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); sqldatareader reader = command.executereader(); //connection.close(); int colcount = reader.fieldcount; while (reader.read()) { (int = 0; < colcount; i++) { console.writeline(reader[i]); } } } }
this works, shows properties of table, rather the data in fields---e.g., varchar, 50 dao, table etc.
if understand correctly want actual data in table, you're querying information_schema gives data tables/columns/whatever...
so query table so:
select * table1
i don't know column names in table if want of columns show can replace * column list:
select col1, col2, col3 table1
where col1, col2 , col3 names of columns.
is going for, or way off mark here?
Comments
Post a Comment