nmaillet 97 Posting Whiz in Training

take it up with the authorities at your school or college

I hope your joking. The last thing most people need in school, is a professor with a chip on their shoulder.

nmaillet 97 Posting Whiz in Training

If you went with your method, you would have something like this:

public void NewCustomer(Customer customer)
{
    ...
    command.Parameters.Add("@name", SqlDbType.NVarChar, 30, customer.Name);
    ...
}

or it could look like this:

public void NewCustomer(Customer customer)
{
    ...
    command.Parameters.Add("@name", SqlDbType.NVarChar, 30, this.Name);
    ...
}

Note that customer.Name references the Customer object you passed in to the method, and this.Name references the Customer object that you are calling the method on. Generally, when you have an instance method (non-static), you perform some action based on the current instance of the class, but when you pass in another object of the same class, which one are you using to update the database with?

I wouldn't necessarily recommend using a static method in this case, but you definately shouldn't be using an instance method with another Customer object as a parameter. Hope that clears things up a bit; if not, let me know.

nmaillet 97 Posting Whiz in Training

Sorry about that.. here's the code..

You're code is still wrong, the OP said nothing about restricting symbols... Please stop, a quick, clean, readable and correct solution has already been offered; your solutions offer very little of that.

nmaillet 97 Posting Whiz in Training

You could do it in the constructor:

public class Customer
{
    private readonly string Name;
    private readonly string Phone;

    private string Number;

    public Customer(string name, string phone)
    {
        if (string.IsNullOrEmpty(name))
            throw new ArgumentNullException("name");
        Name = name;
        ...
    }
}

FYI, the purpose of readonly is to prevent the value from being changed after the class is initialized (the value can only be changed in the constructor).

Also, the newcustomer() method is redundant, you should either have an method with no parameters, like so:

public void NewCustomer()
{
    ...
}

Or use a static method, like so:

public static void NewCustomer(Customer customer)
{
    ...
}

If you use it the way you currently have it, you would be able to reference two customers (possibly the same one) in the method, which is unnecessary and creates confussion for other developpers.

nmaillet 97 Posting Whiz in Training

1 this takes as input any number right?

Not quite, it takes a set of numbers. The while, indicates a loop that repeats as long as "read was successful". It's difficult to determine from the way your post is tabbed, but it probably loops after the "read number" statement.

2 I think that the number should be any number >= 0 ?

That's a fair assumption.

3 for counta and countb will be always 1?
also what does counta = 0 means? It means that counta is zero always?

No, they are set to 0 initially. However the statements:

set counta = counta + 1

and

set countb = countb + 1

indicate that counta and countb increment by 1. So if counta was 0, it would become 1, then if it was incremented again, it would become 2, and so on.

4 there is relationship because for counta and countb to be 1, the number need to be 0??

No, since it is in a loop, counta and countb can be far greater than 1, depending on the number of successful reads. Also, number doesn't need to be 0. The modulo (aka mod) operator gets the remainder. In computer science, this is very important when dealing with integer arithmetic (i.e. integers 1, 2, 10, 10034 and not real numbers 1.2, 3.456, etc.). For instance, 25 / 7 = 3.57... or 3 as an integer (decimal removed, …

nmaillet 97 Posting Whiz in Training

No, that is a single thread. Do a Google search for thread tutorials, there are plenty out there. You generally use the Thread class, although there are others, such as the BackgroundWorker class. Here's a quick example that executes a Run() method on the main thread (the thread your program starts with) and a newly created thread:

using System;
using System.Threading;

namespace ConsoleApp
{
    class Program
    {
        static void Main(string[] args)
        {
            //Initializes a new thread that uses the Run() method.
            Thread thread2 = new Thread(Run);

            Console.WriteLine("Starting thread...");

            //Starts the new thread.
            thread2.Start("Thread 2");

            //Call Run() under the main thread.
            Run("Thread 1");

            //Waits for the second thread to finish executing.
            thread2.Join();

            Console.WriteLine("Done!");
            Console.ReadKey(true);
        }

        static void Run(object obj)
        {
            Random random = new Random();
            for (int i = 0; i < 5; i++)
            {
                Console.WriteLine("{0}: {1}", obj, i);
                //Forces the thread to sleep for a random number of milliseconds (less than 500).
                Thread.Sleep(random.Next(500));
            }
        }
    }
}
nmaillet 97 Posting Whiz in Training

Well kind of... A 2D array is an array of arrays. So the first dimension is an array of Control[]. That is, the first dimension doesn't hold a control, it holds an array Control[]. I hope that makes sense...

nmaillet 97 Posting Whiz in Training

This seems very similar to your last post. In either case, show your code, and explain how you want it broken up.

nmaillet 97 Posting Whiz in Training

I though I did explain that... You know, buffers and stuff...

nmaillet 97 Posting Whiz in Training

You initializes one dimension of the 2D array. You need to initialize each element of that dimension, like so:

TControls[t] = new Control[size];

This is called a jagged array, since each element of the first dimension can have a different length. FYI, C# also has a convention for a rectangular array, like this:

Control[,] TControls = new Control[width, height];

In this case, you don't need to initialize like I mentioned above, since it is handled for you, but it all depends on whether or not your array needs to be jagged or not.

nmaillet 97 Posting Whiz in Training

It's exactly what the title of your post says it is. You need to give the SelectCommand property a command.

Hint: SqlDataAdapter (adapter) has a SelectCommand property and you initialized an SqlCommand class (sqlCmd).

nmaillet 97 Posting Whiz in Training

No, that example you gave shows nested classes, which is completely different from what we have been discussing. Let's simplify a bit, here's a class:

public class Customer
{
    public string str;
}

Here's an equivalent struct:

public struct Customer
{
    public string str;
}

They act the same (for the most part) and the differences are most obvious to developers from a C/C++ or some other low-level language background.

First, a struct is completely stored on the stack (you may want to read up on the stack and heap). A class is stored on the heap, and a pointer to the class object is stored on the stack. You generally want to avoid putting large amounts of data on the stack, as it is much more limited than the heap. That said, there are a lot of benifits when using a struct, but you really need to understand the difference before making that call.

There are quite a few differences other than where they are stored (most of which root from there location in memory) and that is all discussed in the referenced article.

nmaillet 97 Posting Whiz in Training

You are "printing" to two separate PrintStream objects (out and err). In your case, they both output to the same place (i.e. the console, or your IDE's output); however, they both use internal buffers that are dependant on the object. This is the same way files tend to work: data is not guaranteed to be writtern out when you call a print() method, it is stored in the buffer. At some point, data will be written out to the console, but it is handled automatically.

To test this out, try only using out (or err). This should give you the results you expect, as each print statement will be stored sequentially in the same buffer. In order to use out and err, and have them print in the correct order, you'll have to use the flush() method. This forces data in the buffer to be written out, like so:

class ThreeException extends Exception {
    private static final long serialVersionUID = 1L;
    static int count = 0;
    public static void main(String[] args) {
        while(true){
            try{
                if(count++ == 0)
                    throw new ThreeException();
                System.out.println("No Exception");     
                System.out.flush();
            } catch(ThreeException e){
                System.err.println("Three Exception");
                System.err.flush();
            } finally {
                System.err.println("In finally clause");
                System.err.flush();
                if(count == 2) break;
            }
        }
    }
}

This is done this way for performance reasons, and you generally want to avoid calling flush() (especially for files) until you are done with the particular stream, or (as in your circumstance) you want to guarantee data has been completely written to the underlying …

nmaillet 97 Posting Whiz in Training

but how can i use a single parameter i still need to write in all thoose from my windows forms? havnig a class for the customers is prob best but i will still need a function in that class similiar to what i already have?

You would start with a class like so:

public class Customer
{
    public string CustomerNumber;
    public string CustomerOrgNumber;
    ...
}

Your method would look something like this:

public void writeCustomer(Customer customer)
{
    ...
}

Then create, update and pass your customer data as a single parameter like this:

Customer customer = new Customer();
customer.CustomerNumber = "123-45";
customer.CustomerOrgNumber = "67-890";
...
writerCustomer(customer);

The example Customer class I gave is pretty simple, and you should probably use properties, add logic, etc.

nmaillet thank you! can you do that with functions that dont need a return value? because my function only needs the input not change anything ot give back

Yeah, it doesn't matter if there's a return type.

ddanbe commented: Well said! +14
nmaillet 97 Posting Whiz in Training

Take a look at the MSDN article. And try this out:

Sub Main()
    Try
        Try
            Console.WriteLine("Try")
            Throw New Exception("Try")
        Catch
            Console.WriteLine("Catch")
            Throw New Exception("Catch")
        Finally
            Console.WriteLine("Finally")
        End Try
    Catch ex As Exception
        Console.WriteLine("Exception: " & ex.Message)
    End Try
    Console.ReadKey(True)
End Sub

You get the following output:

Try
Catch
Finally
Exception: Catch

This shows that the Finally block is executed in almost all circumstances (with a few exceptions discussed in the linked article). The given program starts by executing the Try block. Since it gives an exception, control is passed to the Catch block. Since the Catch block throws an exception, it will get handed to the next Try Catch block (if one exists) that can handle it. However, before that, the Finally block is executed.

It should be noted that the Finally block gets executed even if there is no exception, and if the Finally block throws an exception, it overrides the Try and Catch block's exceptions.

nmaillet 97 Posting Whiz in Training

A struct wouldn't save any "memory", it would pretty well be equivalent. Depending on the architecture of your system and how the compiler wants to handle it, all data in a struct would be passed on the stack, so it would probably be better to use a class. A class would only require a pointer to be passed, while the class members would be allocated on the heap. FYI, passing a string only passes a pointer, not the entire character array.

Just so you are aware, optional parameter were implemented in C# 4.0 (that is, C# with .NET Framework 4.0). All optional parameters must follow all required parameters and requrie a default value (which can be null for ref types). For instance (not good practice, but shows how it's done):

int Sum(int a, int b, int c = 0, int d = 0)
{
    return a + b + c + d;
}

Then, optional parameters are determined by there order:

Sum(1, 2);       //a = 1, b = 2
Sum(1, 2, 3);    //a = 1, b = 2, c = 3
Sum(1, 2, 3, 4); //a = 1, b = 2, c = 3, d = 4

and you can explicitly reference an optional parameter:

Sum(1, 2, d: 4); //a = 1, b = 2, d = 4
nmaillet 97 Posting Whiz in Training

You'll need to elaborate.

nmaillet 97 Posting Whiz in Training

Hmm, that's interesting... When textBox1 loses focus, are you giving it to textBox2? I would imagine (but never tried it) that when a TextBox gains focus it would reevaluate the property. I'm on my cell, so i can't test anything at the moment.

As for number 3 the handling of the PropertyChanged event is managed by the .NET Binding classes.

nmaillet 97 Posting Whiz in Training

Hmmm, sounds like homework to me... Read the rules, and show some work before expecting any help.

nmaillet 97 Posting Whiz in Training

If you're specifically targeting Windows, you can use Visual Studio Express. If you want to support Mac and Linux as well, you'll probably want to go with MonoDevelop. There are a lot of IDE's out there, just Google it, same goes for quick tutorials on creating desktop applications.

nmaillet 97 Posting Whiz in Training

First, you should be using the MdiChildren property, not OpenForms, and the event is not going to fire at the appropriate times (mainly on closing) for your purposes. I could go deeper into it, but I'd rather recommend you not add anything to an MDI container except MDI child forms (with the exception of menus and toolbars of course). Instead, you should add a menu or toolbar, and use that to perform any actions.

I would actually recommend that you do not use MDI at all. As far as I know, Microsoft is not doing any more development for MDI in .NET, and there are some outstanding bugs yet to be resolved.

nmaillet 97 Posting Whiz in Training

Are you using Windows XP 64-bit or Windows Vista 64-bit? It doesn't work for either one of them. Also, it uses the PC speaker, not the sound card, which could be disabled via the BIOS or a jumper on the motherboard. Try opening of the command prompt, type Ctrl+G and hit enter, you should here a beep...

nmaillet 97 Posting Whiz in Training

You would need to get the index of stopper as well, like this:

int i2 = fileread.IndexOf(stopper, i);

You pass in i so it starts searching the string from that index, which prevents it from returning an index less than i. Then you would take the difference of i2 and i, and pass it in as the length of the substring, like so:

string dd = fileread.Substring(i, i2 - i);

Also, don't forget to check for negative values of i and i2, as that indicates that the string wasn't found in IndexOf(). Another thing, this works fine for small files, but keep in mind that this method allocates an array of characters as large as the file (actually double, since each byte is represented as a char (2 bytes)).

nmaillet 97 Posting Whiz in Training

Try removing line 14, and changing your while loop to this:

for (string line = sr.ReadLine(); line != null; line = sr.ReadLine())

I'm on my cell at the moment, so I can't test anything right now, but it might give some weird results if the last line is empty. I'll try and remember to test it tomorrow...

nmaillet 97 Posting Whiz in Training

Here ya go: Win32 Assembly GUI.

nmaillet 97 Posting Whiz in Training

Maybe... what's alloc?

nmaillet 97 Posting Whiz in Training

That's a good start, but I wouldn't think it would be enough (FYI, I'm more of an application developer and never interned). Client-side scripting (JavaScript) is still extensively used; however, many sites are using server-side scripting as well these days (e.g. PHP, ASP or ASP.NET). Also, AJAX really helped push things along by giving client side scripting the ability to load additional information from a server without having to refresh a page, which made the web seem much more dynamic.

I would definately look into at least those. You should probably try and take some time to look into databases and SQL as well. I would recommend going to a site like W3Schools and going through as much as you have the time for (although their tutorials aren't always the best, you can at least get a good idea of what's out there). The more you know, the better your chances will be right?

nmaillet 97 Posting Whiz in Training

You'll have to set the gdiCharSet in the Font constructor (or in the properties panel if you're using Visual Studio). Through some testing, it looks like 128, 129, 130, 134 and 136 work (I was testing with यह परीक्षण है।, which should be Hindi according to an online translator...). You can find a bit more information on character sets in .NET here. I don't work with character sets and I don't know much about them, so I don't really know why several values work, but I'm sure Wikipedia or something could help if you need more info.

nmaillet 97 Posting Whiz in Training

In what way does it crash? Is there an exception you are getting? I was able to run the program without it crashing. C# can, of course, open any type of file, it's just a bunch of bytes...

Also, might I recommend you avoid using var that heavily. It has some specific uses, but is hardly necessary in this case.

nmaillet 97 Posting Whiz in Training

You'll need to add an explicit refrence to it in the XAML, kind of like using namespace ... ;. The MSDN has some documentation on this here. Basically, you add it to the root element it like so:

<Page
    ...
    xmlns:tk="clr-namespace:Silverlight.Windows.Controls.Toolkit;assembly=<assembly_name>"
    ...
    />

Where you'd replace <assembly_name> with the actual name of the assembly (without the .dll). You then reference it using the namespace you defined (in this case I used tk):

<tk:BusyIndicator/>
nmaillet 97 Posting Whiz in Training

You convert guess to upper-case on line 77, and compare it to the "gameWord" on line 88, which is all lower-case.

There's a few other things with your code that you should fix as well:

  1. You initialize boolArray twice (line 16 and 22).
  2. All elements of an array, in C#, are given their default value (false for bool), so setting each element to false is unnecessary.
  3. There's no need to initialize wordArray on line 30.
  4. Line 50 is unnecessary, as you never use randomNumber.
  5. Line 56 is unnecessary, as ToCharArray() instantiates the array for you.

That's at a quick glance, there may be a few other things. None of them really break your program, but should still be fixed.

nmaillet 97 Posting Whiz in Training

You'll probably have to use COM with Word, aka Word Interop; here's the reference. Note that this requires particular versions of Word to be installed on the client machines. I'm sure there are ways to determine and utilize the version at runtime, although I've never had the need to look into it.

You'll be able to load plain text pretty easily. If you want, you can get formatting information using the Interop libraries; however, it would be pretty near impossible to exactly match the formatting used by Word.

nmaillet 97 Posting Whiz in Training

For something like this you may have to look at the PDF specification. There's also an Acrobat SDK and PDF Library SDK, both of which cost money, and I have no idea what they offer in terms of detecting corruption. From what I understand, 1.7 is the latest specification, although Adobe keeps releasing additional extensions.

The basic structure of the file is pretty simple. At the end of the file, there's a file offset for the document catalog. The document catalog is a dictionary that contains a collection of file offsets for "objects". Objects have a header that defines what it is, and its length. You could check simple things like that; beyond that it will start getting quite involved.

nmaillet 97 Posting Whiz in Training

If you compare the syntax of the GRANT and REVOKE statements, GRANT requires user_specification and REVOKE only requires a user. The difference is that user_sepcification requires user plus the IDENTIFIED BY, while user is just that, a user. Try changing the REVOKE query to:

String query ="REVOKE INSERT,SELECT,UPDATE,DELETE on hms.* FROM '"+MainFrame.dbUser+"'@'"+ip+"';";
nmaillet 97 Posting Whiz in Training

Is this a personal or business plan through your ISP? In either case, you may want to look over your service agreement, as some prohibit users from setting up servers. Whether they monitor and enforce it, I have no idea.

nmaillet 97 Posting Whiz in Training

Well, if you're using the String.split() method, it handles creating the array for you. Maybe explain how you are splitting things up, like do you have to handle each line individually? Or is it all going to be one line? Etc.

If you have to handle the split yourself, then you could created a new array and copy elements over if it happened to become to big. You need to post some more details...

nmaillet 97 Posting Whiz in Training

What have you tried? String.Substring() and Double.Parse() are probably good places to start.

nmaillet 97 Posting Whiz in Training

K... so were you going to tell me what's wrong with it? I'll get you started: the question asks for a class that contains a method, which is called by the Main() method, to calculate premiums. I'm assuming that methods have been covered by the time you got to chapter 11 of a programming book (otherwise they probably wouldn't ask), so maybe you need to go back and read some more. Also, the question is somewhat vague... it asks for the CarInsurance class to hold two variables, and also accept the two variables in the method, which seems unnecessary and redundant.

nmaillet 97 Posting Whiz in Training

Show us some code, and explain the issues you are having.

nmaillet 97 Posting Whiz in Training

Did you assign a OleDbCommand to the OleDbDataAdapter's SelectCommand property? The command builder uses the SELECT query to construct other queries, such as the INSERT INTO query.

nmaillet 97 Posting Whiz in Training

K... it's pretty clear what you want to do, and repeating it again doesn't really help. I also think it's pretty clear that you don't have a fundemental understanding of SQL, or C# for that matter. For instance, your foreach statement is a mess, you could do it one of two ways:

foreach (string strtablename in Tables)
{
    cmdsave.CommandText = "CREATE TABLE [" + strtablename + "]";
    cmdsave.ExecuteNonQuery();
    ...
}

or:

for (int i = 0; i < Tables.Length; i++)
                    //or Tables.Count depending on the type.
{
    cmdsave.CommandText = "CREATE TABLE [" + Tables[i] + "]";
    cmdsave.ExecuteNonQuery();
    ...
}

Although that weird hybrid could work, you really shouldn't; it's inefficient, unnecessary and just bad practice.

Second, take a look at the INSERT statement. It requires VALUES to insert into the table (as Rogachev mentioned). How is it supposed to know what you want to put in there?

PLZ give me a code to read or fetch from one database and insert into new database.

I certainly will not. That's your job, not mine. I gave you a link to a good quick SQL tutorial, which will show you how to properly format your SQL queries; so how's about you take a look at it, and try fixing your code?

nmaillet 97 Posting Whiz in Training

What doesn't work? Are you getting any errors/exceptions? I'm not surprised it's not working, but I'm not going to do your work for you. You should go through some SQL tutorials, for starters. This ones not bad: http://w3schools.com/sql/default.asp.

nmaillet 97 Posting Whiz in Training

Could you be more specific about what is not working? Also, dumb question, but couldn't you just copy and paste the file?

nmaillet 97 Posting Whiz in Training

Inside the else case, before the for-loop, initialize a boolean variable to false. Then inside the for-loop, when a match is found, set it to true. Outside of the for-loop, you can check that variable and if its false, show your message.

nmaillet 97 Posting Whiz in Training

Could you post your current code? From the above code, it looks like it should already handle reasking for a name when it doesn't match anything.

nmaillet 97 Posting Whiz in Training

It won't ever evaluate to false, but the break statement would handle this. The matches() method actually uses regular expressions, which is overkill in this situation. Did you use all caps, because the regex engine in case-sensitive by default? In either case, I would recommend using inputName.equals() or inputName.equalsIgnoreCase() instead (on both line 24 and 28).

nmaillet 97 Posting Whiz in Training

There is an exception being thrown, you can see it by changing your event handler:

private void watcher_Changed(object sender, FileSystemEventArgs e)
{
    try
    {
        ...
    }
    catch(Exception exc)
    {
        MessageBox.Show(exc.ToString());
        //Or Debug.WriteLine(exc.ToString());
        ...
    }
}

The issue is that the FileSystemWatcher fires the event from a different thread then the UI thread. WinForms Control's properties can only be accessed directly from a single thread, which helps prevent concurrency issues. You can use delegates to execute methods on the UI thread, for instance you could do something like this (assuming these methods are in your Form class):

private delegate void watcher_ChangedHandler(object sender, FileSystemEventArgs e);
private void watcher_Changed(object sender, FileSystemEventArgs e)
{
    if (InvokeRequired)
        Invoke(new watcher_ChangedHandler(watcher_Changed), new object[] { sender, e });
    else
        try
        {
            ...
        }
        catch
        {
            ...
        }
}

This simply uses a delegate to call itself. InvokeRequired will return false when the delegate is invoked on the UI thread, so it can continue executing in the else case. It is recommended to execute anything that is going to take time on another thread however. So you could either break this up a bit (I wouldn't recommend it though) or use a BackgroundWorker. The benefit of using the BackgroundWorker is that the DoWork event is called on a separate thread and the ProgressChanged is called on the UI thread, which allows you to update the UI.

nmaillet 97 Posting Whiz in Training

Did you try taking out the parentheses after Next?

nmaillet 97 Posting Whiz in Training

You could use the Tooltip class. To customize its appearance, you'll have to set OwnerDraw to true and IsBalloon to false. Then you would handle the Popup and Draw events. The Popup event gives you a chance to specify the bounds (size) of the Tooltip, and the Draw event supplies a Graphics object to specify how you want it rendered.

nmaillet 97 Posting Whiz in Training

Could you elaborate? I have no idea what you are trying to accomplish.