C Amr Moneim C Amr Moneim - 1 year ago 85
C# Question

how to can use value from SQL-Server by C#

i got value from SQL-Server by this code in C#

SqlDataReader reader = new SqlCommand("select Top 1 Client From _ClientName group by Client order by count(*) desc", sqlCon.ShardDB).ExecuteReader();

how i can use this value again to insert it into other table ?

Answer Source

First, for readability sake, try separating your code into separate lines, like so:

SQLReader reader;
SQLCommand SQLCmd = new SQLCommand();
SQLCmd.CommandText = "select Top 1 Client From _ClientName group by Client order by count(*) desc";
SQLCmd.Connection = sqlCon.SharedDB;

If I understood your comment to Sajeetharan's previous answer, you want to know how to advance to the next result if your query returns more than one. Have you tried SQLReader.Read()?


Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download