|
I have a DataTable which contains Tree-Data with the following Rows
id: int
name: string
parentid: int
Now I need a way, to get only the TreeNodes which have child-nodes.
The SQL-Statement I would use.
SELECT id
FROM table
WHERE id IN
(SELECT parentid
FROM table)
Is there a way to get the same result with a DataView a DataRelation or something else?
Markus
|
|
|
|
|
I think the faster query would be
select distinct parentid from table where parentid is not null
Please use DataView.RowFilter to specify the filter.
Thanks,
Alomgir
|
|
|
|
|
The RowFilter takes an String where I specify something like this.
DataView.RowFilter = "id = 123";
but this would not help, as I know there can be no sub-query in the row-filter.
Can you give an simple example for the RowFilter
for this SQL-Command:
SELECT id
FROM table
WHERE id IN
(SELECT DISTINCT(parentid)
FROM table)
|
|
|
|
|
Please use the query
SELECT distinct parentid FROM table parentid is not null
The C# implementation will be something similar to the following. The code is not tested but the concept is there. Hope this helps.
DataSet ds = new DataSet();
SqlDataAdapter myda = new SqlDataAdapter("TreeView", "server=localhost;database=TreeDb;uid=sa;pwd=;");
myda.SelectCommand.CommandType = CommandType.StoredProcedure;
myda.Fill(ds, "Table");
SortedList slist = new SortedList();
DataView dv = new DataView();
dv.Table = ds.Tables["table"];
dv.AllowDelete = true;
dv.AllowEdit = true;
dv.AllowNew = true;
dv.RowFilter = "parentid <> null";
dv.RowStateFilter = DataViewRowState.ModifiedCurrent;
dv.Sort = "parentid DESC";
IEnumerator iterator = dv.GetEnumerator();
DataRowView drv;
System.Int32 i= 0;
while(iterator.MoveNext())
{
drv = (DataRowView)iterator.Current;
if (! slist.ContainsValue(dr["parentid"]))
{
slist.Add(dr["parentid"].ToString (), dr["table"].ToString ());
}
i++;
}
DataList1.DataSource = slist.GetValueList();
DataList1.DataBind();
Cheers,
Alomgir Miah
|
|
|
|
|
I'm sure there is a class to do what I want in the .NET Framework but I cannot remember what it is called right now.
I am writing a service that will sit and wait for a new file to appear in a specific directory. It will then process the file and move it to an archive directory.
I just need a pointer to the class/method that will allow me to watch the directory. My other solution is to read the contents of the directory every few seconds and process the files, but I am sure there is already a pre-existing solution that will do that for me.
Can any one point me in the right direction? Or is this a fictional class that I drempt up somewhere?
|
|
|
|
|
System.IO.FileSystemWatcher
---
b { font-weight: normal; }
|
|
|
|
|
That's fantastic. Thanks. It was exactly what I was looking for!
|
|
|
|
|
It is the FileSystemWatcher class. It responds to different events such as create, change, renamed etc.
|
|
|
|
|
Hi,
I'm trying to detect if XP themes are enabled or not in code (using .NET 2.0). This not as
easy as it seams, however. I thought Application.VisualStyleState would be
of a lot of help, but unfortunately, it was not.
Basically, I need something similar to this (pseudo-code that might look like VB to some ):
If LegacyOS Then ' Older browsers with no theme support: W2K, W98, WME
return False
ElseIf OsSupportsThemes Then ' For example: XP, 2k3, Longhorn
If ThemesEnabled Then ' Application.EnableVisualStyles was called, or manifest is present
Return True
Else
Return False
End If
End If
Is there a method I'm not aware of in the .NET 2.0 framework, or a good way to do this?
Thanks!
Carl
|
|
|
|
|
Checkout the Environment class.
if(Environment.OSVersion.Platform == PlatformID.Win32NT &&
Environment.OSVersion.Version.Major >= 5 &&
Environment.OSVersion.Version.Minor >= 1) {
Application.EnableVisualStyles();
}
WM.
What about weapons of mass-construction?
|
|
|
|
|
Ok... but if the user is using XP but running in Classic themes... that won't help
|
|
|
|
|
Sorry, I didn't mean to post anonymously!
|
|
|
|
|
It should savely ignore the call anyway
WM.
What about weapons of mass-construction?
|
|
|
|
|
Application.RenderWithVisualStyles ?
|
|
|
|
|
EXACTLY! It works... Too bad I didn't see this property before
Thanks a lot!
On another note, is it possible to get the THEME that is currently displayed? Would be useful for me to theme controls that I'm drawing from code.
|
|
|
|
|
Take a look at the API functions in uxtheme.dll. OpenThemeData gives you a handle to the theme currently displayed. You then pass this handle to all of these functions to draw themed controls.
I hope this helps.
Human beings were not meant to sit in little cubicles staring at computer screens all day, filling out useless forms and listening to eight different bosses drone on about about mission statements. -- Peter Gibbons
|
|
|
|
|
Very useful, thanks! I will definately take a look.
|
|
|
|
|
hi everyone,
i need to write a program (c#) that will do the following:
- list all users existing on the computer
- enter different keys into the windows registry for each of the users (these will be used by another application to enable/disable some of its features).
i could do the first part with ADSI, but this doesn't give me access to the registry or I could access the registry directly, but in this case I don't know how to figure out the keys (and names) of the existing users.
any hints?
thanks,
frankk
|
|
|
|
|
hi,
i'm trying to find a way that i can manage the use of a windows application by making use of an activation code which be used to enable the application and allow the user to use it.
i want to be able to generate a fixed length code of not more than 20 characters..
i have been unsucessfull in searching the web for guidance in this matter...
any help or pointers to articles will be great..
Thanks ,
Afzal Hassen
|
|
|
|
|
It's unlikely that many people will publish their approach to this, because they use it to protect their app. Look into the Cryptography namespace for ideas on established algorithms you can play with to come up with a way to create a code. If you do some sort of hash, never just use the users name, someone will work that out. Put some noise in there.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
that makes sense...
thanks Christian
Afzal Hassen
|
|
|
|
|
Hi
Is it possible to integrate set up file for my project and Windows Service in one set up file
Right now i have made set up files for both individual installer one for my projetc set up file and another set up files for Windows Service
pls tell me the procedure for that
Any help
Urgent
Thanks
Sanjeev
|
|
|
|
|
You could make a separate setup project and add all files to that setup.
I don't know how it works with the service installer, but you should be able to integrate that one into the setup as well.
WM.
What about weapons of mass-construction?
|
|
|
|
|
hi WillemM,
Thanks for your reply.
Do u know how to add both set up file in one set up file
I have made two separate set up files
for both two project
thanks
sanjeev
|
|
|
|
|
Hi!
I'm beginer in visual c# and i have a big problem. Please explain me how to work with an acces database from c#. How to read articles from database, how to write and so on. Thank you!
|
|
|
|