Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Populate Datagrid from Batch File .C#.NET

Status
Not open for further replies.

RJL1

Technical User
Oct 3, 2002
228
0
0
US
We are trying to populate a data grid with information from our terminal server sessions using a batch file to populate our data grid. We are using the QWINSTA command in a batch file and have two version. The first version we tried is

Code:
'qwinsta /server:ILSRF01

This returns an output like this. The issue is that we only need the USERNAME and ID btu each row is one single string.

Code:
SESSIONNAME     USERNAME    ID       STATE      TYPE
rdp-tcp#4       mmoore       4       Active     rdpwd
rdp-tcp#24      ifranco     22       Active     rdpwd
rdp-tcp#39      mlopez      28       Active     rdpwd

The first code works and it populated the data grid but with a single string and we are trying to split it into 5 columns.

The second string return just the user name and session ID which is what we need for our application. It also puts a comma between the two variables which we need. However this fails to populate the data grid.

Code:
for /F "tokens=1,2,3" %i in ('qwinsta /server:ILSRF01 ^| findstr "Active"')do @echo %i | find /v "#" | find /v "console" || echo %j,%k,

The command above returns

Code:
mmoore       4
ifranco     22
mlopez      28

We hope someone can shed some light on what we may be doing wrong or if there is a better way to go about this.

Thanks
RJL
 
I still seem to *not* see what you want to ask. Looks to me that you were able to extract the data you want. Just save it on a file and build the code to parse the file and load it in a datagrid.
 
treat the parsing operation and UI operation as distinct tasks. if you try to bind the file directly to the UI it will be difficult at best.

instead find a way to parse the text file into meaning objects for your system. creating a simple POCO (plain old compiled object) to contain the information from the file abstracts where the information comes from for the rest of the system.

you can then bind a list of POCOs to the UI. something like
Code:
class MyPoco
{
  string username;
  ...
}

class PocoRepository
{
    //use this class to parse the text file

    public MyPoco Get(string id)
    {
    }

    public IEnumerable<MyPoco> All()
    {
    }
}

Jason Meckley
Programmer
Specialty Bakers, Inc.

faq855-7190
faq732-7259
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top