|
you need to oledbconnection
oledbcommand or oledbdataadapter
command="insert into tablename (dateTime)values('"+datetime.date.now()+"')";
Rami Abdalhalim
|
|
|
|
|
Don't double post. See the response you got from Christian.
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
|
|
|
|
|
Hello all,
I wonder if the following problem is possible in c#:
I have two classes named class1 & class2 both having two functions named func1 & func2 . Although the function names are the same, what they do are different for two classes.
I want to declare only one object to use these functions.
In order to do what the following code portion does
class1 obj1 = new class1();
class2 obj2 = new class2();
if (selection == 1)
obj1.func1();
else if (selection == 2)
obj2.func1();
I need a shorter and smarter way i.e;
The above code is possible but it is too long. You should write if statements every time you want to call the functions. So I want to do this with a shorter code:
I have an object which is assigned to the obj1 or obj2 (which are declared as above) depending on the selection at the beginning of the program, then you can call the funcs just by obj.func1()
I dont want to write if statements each time i am calling the functions.
Declaring an object of type object is OK but this time you have to cast the obj which is of type object to class1 (or class2 ) each time you are calling the functions. So casting is a not a solution either. I think i am looking for something like "Permanent casting" (if exists of course)?
P.S : One of the classes may have extra funcs which the other doesnt contain so "Inheritance" is not enough
Regards
Zafer
-- modified at 4:36 Saturday 25th August, 2007
|
|
|
|
|
Create a base class, and two derived classes, then you can call the method, and it's different based on which type of class the instance is.
Christian Graus - Microsoft MVP - C++
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
Thanks for your post Christian.
What if one of the classes have an extra func that the other class does not have. Is it possible to call that function in that case? Because as the object is of type baseclass I will not be able to see it.
Zafer
|
|
|
|
|
Not unless you first check if it's that type, or define those methods in an interface ( which you would still have to cast to ). That's how inheritance works. You CAN define a method in the base class that doesn't do anything in the base class, and then does in derived ones.
Christian Graus - Microsoft MVP - C++
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
|
Define an interface that has those two functions. implement that interface in both classes. cast the selected object to that interface.
public interface fred
{
void func1();
void func2();
}
public class class1 : fred
{...} etc
class1 c1 =...
class2 c2 =...
fred doer;
if (...)
{
doer = c1;
}
else
{
doer = c2;
}
doer.func1();
etc
Philip Painter
|
|
|
|
|
Hi!
i am trying to copy nodes from one xml to another, i am doing a simple action, appending the first xml the node that i want from the other xml using the XmlNodeList(specific node).
I always get the error that this node belongs to another xml document:
"the node to be inserted is from a diffrent document content"
how should i do this copy??
Thanks
|
|
|
|
|
You need to create a new node and copy it into the new document, otherwise, the same node ( as it's passed by reference ) is in two documents, and this is verboten.
Christian Graus - Microsoft MVP - C++
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
You must first Import the node from another doc to yours,you can do that using ImportNode method from from XmlDocumrent instance so it would be somewhat like this
and if you want to create a whole new coy of your node pass deep argument as true otherwise just the selected node would be impoterd not the childs
XmlDocument doc1 = new XmlDocument();
doc1.AppendChild(doc1.CreateElement("MyElement"));
doc1.Save(@"N:\doc1.xml");
XmlDocument doc2 = new XmlDocument();
<code>XmlNode importedNode = doc2.ImportNode(doc1["MyElement"], true);</code>
doc2.AppendChild(importedNode);
doc2.Save(@"N:\doc2.xml");
good luck
|
|
|
|
|
Hi
I have designed an application which creates and uses an encoded XML file as its database.Some times overnothng this file gets damaged. I put a backup service for this app to check the file every 20 seconds and if it finds errors in the file it will restore the backup.The point is sometimes althought the file is broken ,the backup service finds this file as correct.also the program continues working with the file untill it gets closed.After closing the program the problems raise I face a big loss in data.
Could anyone tell me what the problem is and why before closing the app the file seems to be correct but after closing the app file gets corrupted.
Thanks
|
|
|
|
|
Yes, the problem is bugs in your code. We can't really say more without seeing the code.
Christian Graus - Microsoft MVP - C++
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
Hi,
This is my code:
<br />
System.IO.FileStream file=System.IO.File.OpenWrite(_fileName);
System.IO.MemoryStream ms=new System.IO.MemoryStream();
dataset.WriteXml(ms);
ms.Position=0;<br />
byte[] buffer=new byte[ms.Length];
ms.Position=0;<br />
ms.Read(buffer,0,buffer.Length);
ms.Close();<br />
file.Position=0;<br />
file.SetLength(0);
buffer=System.Text.Encoding.UTF8.GetBytes(Encrypter.EncryptData(System.Text.Encoding.UTF8.GetString(buffer)));
file.Write(buffer,0,buffer.Length);
file.Close();
Just one process can write on main file,other processes like backup process may read this file.
|
|
|
|
|
Hi all,
In VB.Net
Dim strTemp as string
strTemp = "today is " _
& " Saturday "
How to do the above in C#.Net?
Thanks
Senthil
|
|
|
|
|
If you can;t work that out, you should be doing a very basic tutorial in C#, or buying a book.
string strTemp;
strTemp = "today is Saturday";
strTemp = "today is " +
"Saturday";
string temp = "today is Saturday, and Microsoft no longer recommends Hungarian notation";
Note, C# doesn't have the stupid rule where you need a special character to show code goes over two lines.
Christian Graus - Microsoft MVP - C++
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
Excellent reply!
|
|
|
|
|
Or even:
string today = "Saturday" ;
string temp = string.Format ( "Today is {0}" , today ) ;
|
|
|
|
|
Yes, using string.Format is good. Seems I've been going down that road lately
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
|
|
|
|
|
And we thank mister Semi Colon for that.
Luc Pattyn [Forum Guidelines] [My Articles]
this weeks tips:
- make Visual display line numbers: Tools/Options/TextEditor/...
- show exceptions with ToString() to see all information
- before you ask a question here, search CodeProject, then Google
|
|
|
|
|
halloo ..
i'm newbie in ADO.Net.
i want to ask about trigger in sqlserver2000.
i develop ado apps with c#. my case is ...
client 1 open add employee form, client 2 open list of data employee.
client 1 add employee data. if client 2 doesnt click button refresh, so new data is doesnt appear, right ? so i want sqlserver make the trigger to the client and auto refresh the list data so that the data auto appear in list without user in client 2 click resfresh button or the application make auto refresh with function.
thanks.
thanks vian.
|
|
|
|
|
It's possible to write .NET code in SQL Server 2005. This MAY allow you to do what you want. In SS2000, it is not possible.
Christian Graus - Microsoft MVP - C++
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
so, what must i do ? could you help me how make the trigger is ?
thanks
|
|
|
|
|
Like I said, SS2000, you can't do it. Your best bet is to poll the database regularly, but of course, this means a lot of network traffic.
Christian Graus - Microsoft MVP - C++
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
Welllll....not quite. It IS possible, but you have to install the SS2000 version of Notification Services. Docs on it are here[^].
I looked at it a few years ago. It'll require him to rewrite a good chunk of his database code to support this though...
|
|
|
|