|
Is frmMain the name of your Form class, or the name of the variable that refers to an instance of the class?
From the error message, it looks like it is the name of the class. And what you need is an actual instance of the class.
You can do this by passing this from the main form class to the database class (I am assuming that the Database class is being instantiated from the form class). Although, from a design perspective, I don't think it is a good idea for a class that deals with the database to get involved with GUI code. (But that distracting from the current problem - So 'nuff said!)
"You can have everything in life you want if you will just help enough other people get what they want." --Zig Ziglar
"On two occasions, I have been asked [by members of Parliament], 'Pray, Mr. Babbage, if you put into the machine wrong figures, will the right answers come out?' I am not able to rightly apprehend the kind of confusion of ideas that could provoke such a question."
--Charles Babbage (1791-1871)
|
|
|
|
|
frmMain is the name of the main class. could you expand on the passing of this because i don't quite understand what you mean.
Also, when you say about the database being involved in the GUI, i don't know any other way because of this problem at the moment. Once this problem is out of the way, there will be a fuctions class or something created with handlers for all the GUI elements.
|
|
|
|
|
this is the implicit object, or the instance of the class from which your code is currently executing. It's, "this" object. This is prevalent in C++, Java, C#, and several other languages. In VB and VB.NET, it's called "Me".
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
i know that much , just what does it mean by passing it to the database class?;P
|
|
|
|
|
If the database class needs an instance of whatever this represents in your context, then you simply pass this to the database class so that it has a reference to that dependent object, something like this:
public class A
{
public A()
{
B b = new B(this);
}
public void SomeMethod()
{
}
}
public class B
{
public B(A a)
{
if (a != null) a.SomeMethod();
}
}
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
cheers, i'll try that.
|
|
|
|
|
thewebmonster wrote:
the GUI class creates an instance of the database class and calls the 'searchdatabase' method
How are you creating an instance of the DB class?
I assume you are doing myDatabaseClass = new DatabaseClass();
Is it the SearchDatabase method that is throwing the exception or is it code inside the method?
Michael
But you know when the truth is told,
That you can get what you want or you can just get old,
Your're going to kick off before you even get halfway through.
When will you realise... Vienna waits for you? - "The Stranger," Billy Joel
|
|
|
|
|
// in the database class
frmMain.listSearchResults.Items.Add(id + " - " + Convert.ToString(myDataRow["name"]));
and it returns the error
database.cs(78): An object reference is required for the nonstatic field, method or propert 'VideoLibrary1.frmMain.listSearchResults'
|
|
|
|
|
hiiiii....all
Assume you have a lan in your office,,,,All the computers there are clients ....and i wanna to develop a software for communuication between clients...the appliaction will have array of the ips of the network,the user selects a specific ip,,,and press (send button) to transfer any file to the Computer with the specific id(Communication may be files or text)
the Communication is two way to,,,as computer A can sends to Computer B and vice versa
i think that UDP is good,,,but i cannot understand it,,
please any one who have developed a software close to that,,Send me Anotification
Thanks,,,,all
|
|
|
|
|
peter micheal wrote:
i think that UDP is good,,,but i cannot understand it
I've never used UDP, but if you're going to be using sockets I think that TCP is a better option.
A good book on Sockets is C# Network Programming by Richard Blum. It describes UDP as a connectionless protocol. A quote from the book: "Connectionless sockets allow the sending of messages in self-contained packets. A single read method reads the entire message sent by a single send method... Unfortunately, UDP packets are not guaranteed to arrive at their desitnation" (pp210)
So, what I understand from this is that something sent via UPD must fit in one packet (typically 1500 bytes, which includes the space reserved for the IP headers) AND if you send a file this way it may not reach its destination. Certainly the books example code for using UDP never sends anything greater that 1kb.
If you are going to do network programming then I do recommend a good book on the subject. The one I mentioned above is an excellent book for use with C#. That way, if you do still have problems then you can be more specific in posting a question.
Back to your problem: You will need to have a process running on each of the clients that is acting as a server (it is able to receive incomming communications). If you say they are all clients you will go round in circles trying to figure out get them to communicate with each other. Always you need a client process (which initiates the request) and a server process (which responds to the request). In your cast a request is sending the file from one computer to another.
Next, you will need some protocol of your own to permit the transfer. You will need to tell the receiving computer (the server) how much data you are going to send at the very least so that it knows when to stop looking for more data. (You may also like to add in things like filename, timestamps, usernames and other relevant metadata) Now, there are off-the-shelf protocols already available in the .NET Framework that will assist you in this, but if you want to use Sockets you will have to do all the hard work yourself.
Does this help?
"You can have everything in life you want if you will just help enough other people get what they want." --Zig Ziglar
"On two occasions, I have been asked [by members of Parliament], 'Pray, Mr. Babbage, if you put into the machine wrong figures, will the right answers come out?' I am not able to rightly apprehend the kind of confusion of ideas that could provoke such a question."
--Charles Babbage (1791-1871)
|
|
|
|
|
I got a text file that i exported from SQL Wizard and i named bank.txt.
i want to write out a program that allow to import bank.txt file to SQL Server but i do not know how to do it.
So can anyone help me or show me where to get the source code.
Thank a lots.
Mr Duc Linh Nguyen
|
|
|
|
|
quocbao wrote:
I don't know import data into Sql server from file text, when user give a file text.
Your question is a little vague as you don't define the contents of the text-file.
Do you want to do this programmatically?
You could use the DTS wizard that comes with SQL Server (Import and Export Data) as this app will pretty much do the job for you.
If you want to interact with the DTS via C# then have a read of HOW TO: Create a Data Transformation Services Custom Task by Using Visual C# .NET[^]
Alternatively, you could read the text file, parse the contents and then squirt the data into SQL using ADO.NET.
Michael
But you know when the truth is told,
That you can get what you want or you can just get old,
Your're going to kick off before you even get halfway through.
When will you realise... Vienna waits for you? - "The Stranger," Billy Joel
|
|
|
|
|
My job requires me to write a an application that will collect data from a Web Form and then dump it into MS Message Queue. May I reqoest help from you experts to show me, after collecting the data from the form, how I could achive that within C# .NET. Do any of you folks have any code snippets?
I am doing C# for only few months and love it but I got stuck here.
Regards,
Login
|
|
|
|
|
Have you look at MessageQueue class?
Mazy
"I think that only daring speculation can lead us further and not accumulation of facts." - Albert Einstein
|
|
|
|
|
I'm using VS .NET and in the solution Explorer i can see a .exe file but i can't find a .dll for the same file. I need the .dll for assembly referencing. Is there a way of creating the .dll when i only have a .exe
|
|
|
|
|
Not unless you rewrite the code to be in a .DLL. The two files have very different entry points and startup routines.
Visual Studio wont let you set a reference to an .EXE, but the commandline compiler, csc, will let you reference an .exe. There was another thread in this forum that spelled this out earlier this week.
RageInTheMachine9532
|
|
|
|
|
Just try renaming it from exe -> dll should be ok dll -> exe will obviously not.
top secret
|
|
|
|
|
In the following code pTable is of type CustomerTable, which inherits from DataTable. How can I change the "if" statement to check that pTable is derived from DataTable as the statement currently tests false, because the types are different. I thought I would cast ptable, but the of course that would throw an exception if that cast is invalid.
if (pTable != typeof(DataTable))
{
throw new EwGeneralException(lStk, EwExceptionID.DdlNotDataTable);
}
Many thanks for reading.
Nursey
|
|
|
|
|
Can you try
if (typeof(pTable).BaseType !=typeof(DataTable))
....
James
|
|
|
|
|
You're comparing apples and oranges, there. pTable is an instance, and the typeof operator will always return a Type , so the two would never match unless pTable was a variable which held a Type .
If you want to check is something is an instance of a particular type, simply use the is operator:
if (pTable is DataTable)
{
} You can also use something like this, although it requires more code and more instructions (when compiled to IL):
if (pTable != null)
{
if (pTable.GetType() == typeof(DataTable))
{
}
} There's other ways of doing this, but you don't have to take inheritance into account. If CustomerTable inherits form DataTable , then any instance is a type of CustomerTable , DataTable , MarshalByValueComponent , and - as with everything in .NET - Object . It's also an instance of any interfaces that any classes up the inheritence hierarchy implement.
This isn't true going down the hierarchy, though. For example, if you instantiate a new instance of a DataTable , then it is not an instance of a CustomerTable .
Also keep in mind that it's not the declaration that counts, its the definition. For example:
object o = new DataTable("Example"); While o is declared as an object , it's still an instance of a DataTable . Calling o.GetType will return System.Data.DataTable . This is polymorphism.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
I've developed a simple attribute EwBindSkipAttr which is then used on an abstract member of a class, in the hope that all derived classes which must then implement this member will inherit the attribute on their overriding members. This seems to be correctly implemented...the documentation states that the default is for derived and overriding members to inherit attributes. Here's my simple attribute in use...
///
/// Return DDL wrapper for table
///
[EwBindSkipAttr]
public abstract DataDDL DDL{get;}
The problem is that in the derived classes I have behaviour which indicates that the attribute has not been inherited. Any thoughts please?
Nursey
|
|
|
|
|
Attributes are inheritted by nature, but code which gets and uses these attributes - like MemberInfo.GetCustomAttributes - provide parameters that specify whether or not the calling code wants to get inheritted parameters.
What behavior is this that you mention? There's many things that can contribute to problems you're facing. Remember, attributes don't provide functionality to Types, they merely extend the metadata of a Type so that if something asks for it the attribute and its data is returned. Simply attributing your class with a custom attribute certainly won't do anything if nothing asks for it and uses it.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Hi Everybody - Happy Easter, have a peaceful weekend...
I'd like to ask, to what extent do you use the XML tags in your code (such as summary etc.)
I wonder if you could point me to some code that you consider "model" in its illustration of good practice. Also, do you use any additional tools.
I have a developed an architecture that I consider elegant and simple to use, but to maintain it, it would require good documentation. I would welcome any thoughts and guidance so I can get past my basic use of summary and parameter tags.
Many thanks.
Nursey
|
|
|
|
|
At least document everything public and protected, anything which can be seen by other code. Use all relevent XML tags. This includes, obviously, the <summary> . If your method has parameters, then use the <param> tags. If you return values, use the <returns> tag. If you explicitly throw an exception or let one slide that you want to make sure developers know is possible, use the <exception> tags. Basically, use any tags that are relevent to the to member. If you want to provide more information about something, then use the <remarks> and/or <example> tags.
For a great and free documentation compiler, see NDoc[^]. I've had the pleasure of working on it and I know this product is stable. Just look at the huge list of clients, including Microsoft. It can generate many formats like HTML Help 1 (ex: VS6 docs) and 2 (ex: VS7+ docs). It looks just like the current VS.NET / MSDN documentation as well.
For larger products in a corporate environment, you might consider abstracting all comments away to separate files. Then use the <include> tag to specify an XPath expression that imports the documentation. This seems to be what Microsoft does since many members - especially overloaded methods - share the same content for various sections.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Hand, Stop, and Error all use the big X.
Warning and Exclamation share a triangle with an exclamation point.
Asterisk and Information share a bubble with a lower case 'i'.
Does this provide the option for me to replace these icons with my own?
|
|
|
|
|