|
How do I put a string into a xml file in a windows application, in a window form? I use a DataReader and not a dataset.
the code looks like this:
I have a XmlDocument myXml
............
string sqlString=" SELECT NumeMat,NumeCD,durata, nrstud "+
" FROM materii AS m, corpdidactic AS cd, activitate as a"+
" WHERE m.IDMat = a.IDMat AND cd.IDCD = a.IDCD"
+
" ORDER BY IDAct";
SqlCommand sqlCmd=new SqlCommand(sqlString, sqlConn);
SqlDataReader sqlDr=sqlCmd.ExecuteReader();
string result=
""+
"<activitati>";
string pageContent="";
while(sqlDr.Read())
{
string activ= "<activitate>\n"+
" <numemat>"+sqlDr["NumeMat"].ToString()+"\n"+
" <numecd>"+sqlDr["NumeCD"].ToString()+"\n"+
" <durata>"+sqlDr["durata"].ToString()+"\n"+
" <nrstud>"+sqlDr["nrstud"].ToString()+"\n"+
"\n";
pageContent=pageContent+activ;
result=result+pageContent;
}
sqlDr.Close();
result=result+"\n";
how can I put "result" in myXml.xml???
When I was working to a project in ASP, I used DocumentContent property....
|
|
|
|
|
You've already got your string (although your multiple concatenations are horribly inefficient - take a look at the StringBuilder instead), you just have to write it to a file. The easiest way is to just use a StreamWriter with a new file and use Write . See the classes in the System.IO namespace for additional options. This is just a simple I/O scenario.
Note, using an XmlTextWriter would really only be useful if you used WriteRaw . You've already got your XML in a string, so there's no reason to parse that and create the elements and attributes. Just use a basic TextWriter (or rather a derivative class).
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Hey
Is there anyone that knows of a simple way to change color on the background of an object in the listbox?
I know how to changes the color of the Text, but not the bakground.
//Jimmy
PS Im not to god on this control Manupulations so explain well =)
|
|
|
|
|
ListBox.BackColor perhaps?
If you want to control the background color of a particular item, you'll have to use owner drawing by setting DrawMode to something besides DrawMode.Normal and handling the DrawItem event, or overriding the OnDrawItem method in a derived class.
There's many examples of this on CodeProject. Just search for "ListBox" or something.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Yes i found how to do that, lookt throw the difrent methods in grafic and found that i could just bound to fill the item with color.
Thanks alot for helping =)
//Jimmy
|
|
|
|
|
So call FillRectangle first, then call DrawString . Always worked for me.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Can someone explain to me how interfaces are such a big help in creating objects? I was under the impression that an Interface was a template for an Object, just sort of a class with only method signatures
inside them, not actual code inside the methods. But from seeing code and hearing bits and pieces from individuals, they are more than that.
Please enlighten me oh coding gods and gurus.
Thanks,
JJ
|
|
|
|
|
Interfaces are contracts. They define methods, properties, and events that a class must implement in order for callers to use certain features. Classes can only extend one class in .NET, but structs and classes can implement as many interfaces as you want.
Take IList for example. Since it inherits form ICollection and IEnumerable , this means that any class that implements IList is enumerable and has methods and properties that let you add, remove, and index items, as well as clear them. This fosters a good OO design because a caller doesn't have to know the exact Type of an object to use its methods.
For instance, the DataGrid.DataSource accepts an Object . Internally, it checks if this object supports IList or IListSource . It doesn't care if it is a DataSet , an array, or any collection. Just that it supports one of those two interfaces.
This is very handy for creating abstract implementations like plug-ins. You don't need to know a specific Type at design-time or run-time, just that it suports a particular interface. Lets say an application that can uses plug-ins reads a list of Types from the configuration file and defines an interface like so:
public interface IPlugin
{
void Initialize(Control parent);
string Caption { get; }
} Then when the applications get each type, it can do something like this:
IPlugin plugin = (IPlugin)Activator.CreateInstance("some type");
plugin.Initialize(this); It doesn't need to know the Type, just that the Type implements the interface (you should catch exceptions though, in case the cast fails).
For more information about plug-ins, which are a good example of interfaces, try searching[^] CodeProject.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Thanks Heath,
I found out where my confusion is. See I had noticed in code the follwoing:
public class MyClass: System.windows.form{
}
and I thought what is on the right of the colon was an interface
System.windows.form and was wondering how it could benefit MyClass if it
was an interface but has no defined methods in it. But I was mistaken its a base class that has methods and properties to use from it.
JJ
|
|
|
|
|
Hi all,
I would like to implement this interface for my C# Class,The IDropTarget interface has been created, as shown below.
[ComImport,
Guid("00000122-0000-0000-C000-000000000046"),
InterfaceType(ComInterfaceType.InterfaceIsIUnknown) ]
public interface IDropTarget
{
[PreserveSig()]
int DragEnter(IDataObject pDataObj, uint grfKeyState, object pt, ref uint pdwEffect);
[PreserveSig()]
int DragOver(uint grfKeyState, object pt, ref uint pdwEffect);
[PreserveSig()]
int DragLeave();
[PreserveSig()]
int Drop(IDataObject pDataObj, uint grfKeyState, object pt, ref uint pdwEffect);}
Compiles without any problem.
However when I try to register:
[DllImport("ole32.dll")]
static extern int RegisterDragDrop(IntPtr hwnd, ref IDropTarget DropTarget); gives an error saying Expected (ret code is highlighted as error) Expected class ,Delegate ,enum,Interface or struct.
However, changing the int enum gives the same Error.
The function is actually defined as
WINOLEAPI RegisterDragDrop(
HWND hwnd, //Handle to a window that can accept drops
IDropTarget * pDropTarget
//Pointer to object that is to be target of drop);
WINOLEAPI on further examination turns out to be HRESULT with 3 values 0,1,2
What am I doing wrong ?
Could any one please help ? thanks in advance.
Thanks
Ven
|
|
|
|
|
For one, you don't need to ref the IDropTarget in RegisterDragDrop - it's already a reference Type so passing an instantiated instance. This could be one of the problems.
Second, in your IDropTarget , are you using the IDataObject defined in the .NET base class library, or an interop'd one that you'd have to define like you are with IDropTarget . Though the OLE interfaces are used internally by .NET, the IDropTarget interfaces are vastly different.
As far as the error, returning int should be no problem. An HRESULT is a 32-bit signed integer. Preserving the signatures of all the IDropTarget methods isn't necessary, either. This really is only helpful if you need to return a success code that isn't S_OK (0). Even in this case, though, you can always throw a COMException with the error code (or success code), which is the correct way (at least for errors). This can provide additional information to the caller if they support IErrorInfo . This behavior is provided in part by the CLR.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Thanks Heath,
1.I have started without ref in the IDropTarget didnot help.
2.Have defined the IdataObject locally in the file as [ComImport(),ComInterface]
3.My actual problem is compilation error at static extern int<- RegisterDragDrop
changing the retcode to void,enum etc is not changing the error.
Even DllImport("ole32.dll",PreserveSig=false"} still gives the same error at
the same place.
hope i have explained the problem. Appreciate your help anyway. thanks again
|
|
|
|
|
Regardless of whether or not the ref was a problem, it still shouldn't be there. Now, if this was a pointer to a pointer (i.e., IDropTarget **), then you should use ref . A pointer to a value type (i.e., numeric, boolean, byte, char, struct, enum) would require ref or out .
As far as the error goes, let me introduce you to ildasm.exe - the IL disassembler that comes with the .NET Framework SDK. As I mentioned before - and which should be evident since .NET supports drag-n-drop with native Windows - .NET uses the OLE drag-n-drop internally. Logically, you should think to look into the assembly that would use it (just trying to introduce a thought process here). Logically, this is in the System.Windows.Forms.dll assembly.
So, run ildasm.exe and open that assembly (or use something like .NET Reflector). Find the UnsafeNativeMethods class (typical name in base class libraries). There'll you'll find the defnition used by Microsoft (which obviously works). you'll also find reference to IOleDropTarget , which is what they use internally for IDropTarget (the name doesn't matter - only the IID and methods / dispids depending on inheritence). If ever you have problems determining how something should be defined, changes are that the base class libraries are using them internally somewhere.
The method should be defined as:
[DllImport("ole32.dll", CallingConvention=CallingConvention.Winapi)]
static extern int RegisterDragDrop(HandleRef hWnd, IOleDropTarget target); See nested interfaces for definitions of the interfaces, too. They use "Ole" in the interface name and prefix the method names with it (to help distinguish it from implementations), but it doesn't matter so long as the vtable order for IUnknown-inherited interfaces and DISPIDs for IDispatch-inherited interfaces remain the same (for dual interfaces, both order and DISPIDs should be the same).
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Thanks Heath.
You have been helpful, I would follow your advice. Thanks again..
|
|
|
|
|
Hi, I am trying to use ILAsm and ILDasm inside an application and I need to be able to run the programs and intercept any errors and/or output that they create. Are there FxCL classes to do this or is there another way? (I'm using C#). I searched around on the articles on the site but couldn't find anything relating to this. Maybe I just don't have the right keywords. Any links or advice would be great. Thanks.
-Noah Fields
|
|
|
|
|
Take a look at the System.Diagnostics namespace, especially the Process and ProcessStartInfo classes.
Searching for those two classes on the net should lead you to lots of examples on how to start applications and redirect their output to yourself.
I, for one, do not think the problem was that the band was down. I think that the problem may have been that there was a Stonehenge monument on the stage that was in danger of being crushed by a dwarf.
-David St. Hubbins
|
|
|
|
|
Great! thanks for your help
|
|
|
|
|
is dataset and recordset the same thing? how r they different?
CODER
|
|
|
|
|
A DataSet is a disconnected recordset. All the data is contained in the DataSet so you don't need to fetch from the server again. This makes serialization (either to a file or for Web Services / Remoting) easy, as well as using diffgrams (change records in a DataSet ) to update a data source using a DataAdapter ( or handling it yourself ).
See the section on ADO.NET in the .NET Framework SDK for more information.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
hello all,
Its a well known fact that Panels in ASP.NET can be controlled using <asp:linkbutton> control. My questions is if we could control those same Panels using the <asp:radiobutton> control.
Now this should be done in this way:
1. Lets say there are 4 RadioButtons(of the same group) and 4 corresponding panels.
2. User chooses a RadioButton.
3. The corresponding panel opens up.
NOT in this way:
1. There are 4 RadioButtons(of the same group), 4 corresponding panels and a regular button.
2. User chooses a RadioButton.
3. User clicks on the regular button (lets say its the "Submit" button).
3. The corresponding panel opens up.
Any input is appreciated.
Regards,
Tiruvan
|
|
|
|
|
This has little to nothing to do with ASP.NET - this requires client-side scripting. ASP.NET is a service that runs on the server. Without fetching a new page, ASP.NET isn't involved (this is the nature of HTTP). You can generate a class that exhibits this behavior by emiting a script that reacts to the 4 radio buttons and uses scripting and CSS styles to show and hide the panels (all of which must be written to the HTML writer) appropriately.
Fortunately, Microsoft has already unofficially done this. See the Microsoft IE WebControls at http://www.asp.net/ControlGallery/default.aspx?Category=38&tabindex=2[^]. The MultiPage and TabStrip controls are what you would want.
BTW, this question would be more appropriate in the ASP.NET forum.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
I've got an annoying problem happening. I'm trying to design my user interface and I've got various controls which dock this way and that, and when i compile and run the app, while the window resizes smoothly, the controls that should be sizing to match the window size seem to trying to snap to an invisible grid as they go, which means the distance between the edge of the control and the border of the window keeps changing when the window is resized. It doesn't affect the functionality of course, but it's kinda ugly the way it happens and doesn't really look very elegant. Does anyone have a way around this? Note that I haven't even written any code yet, this is the very start of the app, and all i've done is added some controls and set their docking properties.
NATHAN RIDLEY
Web Application Developer
email: nathan @ netlab.com.au
[remove the spaces before and after the @ symbol]
|
|
|
|
|
Hmm docking, what docking control are you using?
leppie::AllocCPArticle("Zee blog"); Seen on my Campus BBS: Linux is free...coz no-one wants to pay for it.
|
|
|
|
|
actually I made a mistake, I needed to set the integralHeight property of the child control to false. Confused the hell out of me until I noticed it sitting there in the properties box!
NATHAN RIDLEY
Web Application Developer
email: nathan @ netlab.com.au
[remove the spaces before and after the @ symbol]
|
|
|
|
|
Mabey you should use
listView.Items.Clear();
Hope it helps
Thomas
|
|
|
|
|