kplcjl 17 Junior Poster

You'd think 1000 would accurately represent 1 second. I found that if I compared ticks to the starting tick value that my elapsed time timer would occationally jump 2 seconds using 1000. By the time 5 minutes elapsed, you'd probably be off by about 5 seconds using this minute second process. On a timer that is dependent on human reactions, this code is fine, it'll be at most 5 seconds slow and if you use the minute/second method used here to display your time, you'd never have a clue your time is at all off.
(Since I didn't use UTCNow, my timer could jump an hour ahead or backwards. Wasn't thinking of anyone playing with code at 2AM on two special days a year when I wrote it and didn't set up the timer to display hours so you'd see 60+ minutes going forward.)

kplcjl 17 Junior Poster

What riahc3 said makes sense. Worrying about string performance in a textbox event handler is pretty dumb.

However knowing WHEN to worry about performance also makes sense. For personal interest, I was working on a mathematical puzzle and I wanted to see just how much work was being done to solve it. I also wanted to see just how much not using StringBuilder impacted the performance so I intentionally put the string together by adding int fields and text describing what the int fields tell me.

I finally figured out the logic and got a program that completed in 27+ minutes. Putting in the StringBuilder logic cut it down to 14+ minutes. Changing the logic to NOT convert the stats into a string until a final answer was found (Or debug request to SEE the individual steps was made.) cut it down to 7 minutes. Playing around with the order in which numbers are solved cut it down to 4 minutes. Getting a new machine that was twice as fast cut it down to 2 minutes.

kplcjl 17 Junior Poster

The following doesn't make sense:

            do
            {
                next = response.Content.IndexOf("\"", first);
                /*Not neccesary but in case Dani changes the array to something else....*/
                if (next==-1)
                {
                    break;
               }
            } while ((next==0));

I'm not a fan of do whiles, but even if Dani changes things around this is only going to add another useless if statement every time next is zero that doesn't help or improve this:

do {next = response.Content.IndexOf("\"", first); }
while ((next==0));

PS What's with the extranious parentheses?
PPS If first IS 0 and next is set to 0, how is this NOT an infinite loop even if you added the break logic? if first is > 0, how does the while ever become true to even loop once?

kplcjl 17 Junior Poster
    /// <summary>
    /// Binary sort method with custom modifications. Recursive code splits array hopefully in half
    /// and calls each half to sort them.
    /// </summary>
    /// <param name="ar">int array to be sorted</param>
    /// <param name="start">Starting index location in the array to be sorted</param>
    /// <param name="end">Ending index location</param>
    public static void BinSort(int[] ar, int start, int end)
    {
        int middle, middlel, middlevalue, hold, left, right, swapl, swapr;
        if (start > end)
        {
            hold = start;
            start = end;
            end = hold;
        }
        if (start < 0) start = 0;
        if (end >= ar.Length) end = ar.Length - 1;
        middle = (start + end) / 2;
        left = middle - 1;
        right = middle + 1;
        if (ar[start] > ar[end]) Swap(ar, start, end);
        if (ar[middle] > ar[start] && ar[middle] > ar[end]) Swap(ar, middle, end);
        else if (ar[middle] < ar[start] && ar[middle] < ar[end]) Swap(ar, middle, start);
        middlel = middle;
        middlevalue = ar[middle];
        //left moves lower, right moves higher. middlel/middle point to the middle value(s) that won't be sorted when this finishes
        //start end don't change from this point forward
        bool finished = false;
        while (!finished)
        {
            while (left >= start && ar[left] < middlevalue) left--;
            while (right <= end && ar[right] > middlevalue) right++;
            if (left >= start && ar[left] == middlevalue) Swap(ar, left--, --middlel);
            if (right <= end && ar[right] == middlevalue) Swap(ar, right++, ++middle);
            if ((left >= start && ar[left] > middlevalue) && (right <= end && ar[right] < middlevalue))
                Swap(ar, left--, right++);
            if (left < …
kplcjl 17 Junior Poster

I said it was an inefficient sort. It took me a while to figure out the logic because it isn't an easy approach.

I knew it was an efficient sort, but I have to admit to being blown away by how fast it is.

Here are the results for the binary sort method: (After I tweaked out the bugs I wrote into it.)
I just had to move the 200K sort result to the front. (Remember, over two minutes for the original bubble sort):
Time to run binary Sort logic: 00:00:00.0468001

Time to generate and copy two arrays: 00:00:00.0156000 of size: 10000
Time to run original BubbleSort: 00:00:00.3276006
Time to run alternate BubbleSort logic: 00:00:00.2496004
Time to run binary Sort logic: 00:00:00
4987 Values were moved earlier in the array, 5009 were moved later 4 didn't move.

Time to generate and copy two arrays: 00:00:00 of size: 10000
Time to run original BubbleSort: 00:00:00.3432006
Time to run alternate BubbleSort logic: 00:00:00.2340004
Time to run binary Sort logic: 00:00:00.0156000
4966 Values were moved earlier in the array, 5034 were moved later 0 didn't move.

Time to generate and copy two arrays: 00:00:00 of size: 200000
Time to run original BubbleSort: 00:02:20.8994457
Time to run alternate BubbleSort logic: 00:01:37.8277706
Time to run binary Sort logic: 00:00:00.0468001
99997 Values were moved earlier in the array, 100002 were moved later 1 didn't move.

Since I seem to have trouble posting …

kplcjl 17 Junior Poster

When I read the title, I had already figured out how to wrap when the whole word wouldn't fit on a line.
I hadn't figured out how to find the split points on a word so it puts part of the word on the fir-
st line and finishes the word on the next line. Shoot.

kplcjl 17 Junior Poster

Time to generate and copy two arrays: 00:00:00.0060004 of size: 100000
Time to run original BubbleSort: 00:00:30.8487644
Time to run alternate version of BubbleSort: 00:00:22.8873090
nOrig/nAlt/nOrig loc. Values of both versions of BubbleSort with orig: -1073710058/-1073710058/-211269798 Location 0
nOrig/nAlt/nOrig loc. Values of both versions of BubbleSort with orig: 1073739711/1073739711/-859760482 Location 99999
nOrig/nAlt/nOrig loc. Values of both versions of BubbleSort with orig: 2103826/2103826/-203978619 Location 50000

Time to generate and copy two arrays: 00:00:00.0060004 of size: 100000
Time to run original BubbleSort: 00:00:30.7497588
Time to run alternate version of BubbleSort: 00:00:22.7653021
nOrig/nAlt/nOrig loc. Values of both versions of BubbleSort with orig: -1073641870/-1073641870/333869880 Location 0
nOrig/nAlt/nOrig loc. Values of both versions of BubbleSort with orig: 1073714370/1073714370/298019800 Location 99999
nOrig/nAlt/nOrig loc. Values of both versions of BubbleSort with orig: -5930808/-5930808/222613449 Location 50000

Doubling the size of the array should quadruple times:
Time to generate and copy two arrays: 00:00:00.0120007 of size: 200000
Time to run original BubbleSort: 00:02:11.1024987
Time to run alternate version of BubbleSort: 00:01:33.2273323
nOrig/nAlt/nOrig loc. Values of both versions of BubbleSort with orig: -1073728914/-1073728914/24513230 Location 0
nOrig/nAlt/nOrig loc. Values of both versions of BubbleSort with orig: 1073740987/1073740987/-516876871 Location 199999
nOrig/nAlt/nOrig loc. Values of both versions of BubbleSort with orig: 1911366/1911366/-497207514 Location 100000

kplcjl 17 Junior Poster
    /// <summary>
    /// creates a random array of positive/negitive numbers of the specified size
    /// </summary>
    /// <param name="sizeArray">Size of the array to generate</param>
    /// <returns>The created array</returns>
    public static int[] GenRandVals(int sizeArray)
    {
        if (sizeArray <= 0) throw (new Exception(string.Format("GenRandVals(int sizeArray) called. sizeArray MUST be > 0. Value= {0} sent.", sizeArray)));
        int[] vals = new int[sizeArray];
        int range = int.MaxValue, diff = range / 2;
        Random rand = new Random();
        for (int i = 0; i < sizeArray; i++)
            vals[i] = rand.Next(range) - diff;
        return vals;
    }
    /// <summary>
    /// copies values from one array into another one
    /// </summary>
    /// <param name="ar">The array to be copied</param>
    /// <returns>copied array</returns>
    public static int[] CopyArray(int[] ar)
    {
        int len = ar.Length;
        int[] Cpy = new int[len];
        for (int i = 0; i < len; i++)
            Cpy[i] = ar[i];
        return Cpy;
    }
    static void Main(string[] args)
    {
        DateTime start = DateTime.Now;
        int arraySize = 200000, loc = 0;
        int[] testArray1 = GenRandVals(arraySize), testArray2 = CopyArray(testArray1), testArray3 = CopyArray(testArray1);
        TimeSpan span = new TimeSpan(DateTime.Now.Ticks - start.Ticks);
        Console.WriteLine(string.Format("Time to generate and copy two arrays: {0} of size: {1}", span.ToString(), arraySize));
        start = DateTime.Now;
        BubbleSort(testArray1);
        span = new TimeSpan(DateTime.Now.Ticks - start.Ticks);
        Console.WriteLine(string.Format("Time to run original BubbleSort: {0}", span.ToString()));
        start = DateTime.Now;
        AltBubbleSort(testArray2);
        span = new TimeSpan(DateTime.Now.Ticks - start.Ticks);
        Console.WriteLine(string.Format("Time to run alternate version of BubbleSort: {0}", span.ToString()));
        Console.WriteLine(string.Format("nOrig/nAlt/nOrig loc. Values of both versions of BubbleSort with orig: {0}/{1}/{2} Location {3}",
            testArray1[loc], testArray2[loc], testArray3[loc],loc));
        loc = arraySize - 1;
        Console.WriteLine(string.Format("nOrig/nAlt/nOrig loc. Values of …
kplcjl 17 Junior Poster
        /// <summary>
        /// Alternate version bubble sort
        /// </summary>
        /// <param name="ar">int array to be sorted</param>
        public static void AltBubbleSort(int[] ar)
        {
            int endpoint = ar.Length - 1;
            for (int i1 = 0; i1 < endpoint; i1++)
                for (int i2 = i1 + 1; i2 <= endpoint; i2++)
                    if (ar[i1] > ar[i2])
                        Swap(ar, i1, i2);
        }
        /// <summary>
        /// swap two items of an array
        /// </summary>
        /// <param name="ar">int[] array to work a swap</param>
        /// <param name="i1">First of two positions to swap</param>
        /// <param name="i2">Second position</param>
        private static void Swap(int[] ar, int i1, int i2)
        {
            int hold = ar[i1];
            ar[i1] = ar[i2];
            ar[i2] = hold;
        }
kplcjl 17 Junior Poster

hasnain..., I agree it's a very easy approach. However, I say it is a very INefficient approach. In type O notation it is N^2 which is bad. I tried to show an alternate approach that in O notation is still N^2 but would still be twice as fast. There are alternate methods that aren't an easy approach but in O notation is logn. Dani made me lose my last post so I'll send a code only note later. (Have to rewrite it.) I estimated a million int array would take over an hour and 20 minutes on my machine so my alternate solution would take about 40 minutes. A logn process might take less than a minute. 100k array would finish a 100 times faster. So 50 seconds with his version and 25 with my (still bad) version.

kplcjl 17 Junior Poster

I take it you don't want to allow clipboard copy on the key events?

kplcjl 17 Junior Poster

I do have a question. In your regex expression you have [0-9a-zA-Z] sprinkled throughout. Since you also have ", RegexOptions.IgnoreCase" wouldn't [0-9a-z] serve just as well?
If it doesn't, why do you use IgnoreCase?

I might add, this might not work so well on the international front.
FYI Your no_blank validation could be applied to the first two textboxes as well

kplcjl 17 Junior Poster

kimbula last posted 2 years ago, hasn't responded to suggestions since. Why would (s)he care about suggestions now? My suggestion 2 years ago avoids all the try/catch logic because it is encapsulated in int.TryParse. (Still need error handling, but number handling is built into the numbers themselves. Seems dumb to use anything else when built-in functionality comes directly from .NET.)

kplcjl 17 Junior Poster

Actually, I misread what you had. Your second class IS the event handler, your form subscribes to the event delegate and at the same time makes it not null in your class so it can pass the event back to the form.

kplcjl 17 Junior Poster

EventHandlers are one form of a delegate.
ShapeValueChanged is the delegate.

The following is the subscription of the delegate to the Form1_ShapeValueChanged method:
ShapeValueChanged += new EventHandler(Form1_ShapeValueChanged);

The forms detects an event change and calls the event handler ShapeValueChanged which calls all the subscriptions to it. In this case, only one subscription.

kplcjl 17 Junior Poster

OK, you found a solution, but nobody suggested a delagate. I tried to build a puzzle solving code and display intermediate results and display them on my WinApp form. Didn't do a thing. Turns out, the form thread has to be idle to display changes and I wanted intermediate results not the final ones.

Now the puzzle solving app (PA) is completely separate from my form, so it can be run for any kind of UI. My form subscribes to the delegate and if it asks the PA to show intermediate results, the PA calls the delegate passing a byte array and a text array and then sleeps for the length of time the form asks for. (The PA will allow sleeping for an hour, the form will only ask to sleep up to 10 seconds.) The form wakes up moves the bytes and strings into text boxes and then exits. (Letting the form to sleep again. The sleep refreshes the text box displays.)

SoftwareGuy commented: Thank you for adding insight and an alternative to a problem, even after the thread was closed. +2
kplcjl 17 Junior Poster

OK, people (including me) are talking to you like you would understand what we are saying. That's not working. Think of scope, I moved the arrays outside of the main routine to make the arrays globally available. Others said you should use the for loop to reach all the arrays in parallel. That's correct, I've supplied a routine to show how that works. In that routine, "i" is an iterator. I used "i" over and over to show its scope is local and independent in each of the routines. Check out and understand what "i" is doing in each of the arrays. Someone else said you could use the foreach but then you would have to independently maintain the iterator. That's true too. Didn't give an example on how that would work.

/// <summary>
        /// parallel array of class names
        /// </summary>
        private static string[] classes = { "CS150", "CS250", "CS270", "CS300", "CS350" };
        /// <summary>
        ///  parallel array of people currently enrolled in each class.
        /// </summary>
        private static int[] currentEnrolled = { 18, 11, 9, 4, 20 };
        /// <summary>
        ///  parallel array of maximum enrollment in each class.
        /// </summary>
        private static int[] maxEnrollment = { 20, 20, 20, 20, 20 };
        /// <summary>
        /// Goes through the currently enrolled count and sums it.
        /// </summary>
        /// <returns>total enrolled in all classes</returns>
        private static int currentEnrollment()
        {
            int enrolled = 0;
            foreach (int i in currentEnrolled)
            {
                enrolled += i;
            }
            return enrolled;
        }
        private static …
kplcjl 17 Junior Poster

In the body of your code, you have defined a byte array called currentEnrolled. This data is only in the scope of your main function, it's invisible elsewhere.

Further on compressed code:
public static string checkClassSize() { byte currentEnrolled;
for (i = 0; i < Array.currentEnrolled; i++ ) { Console.WriteLine(i); }}

This currentEnrolled has nothing to do with the other. "i" isn't declared, don't see how this could compile. Array is a collections type that does not have a property or function called currentEnrolled, again, won't compile, you are writing out what appears to be the iterator insead of the non-existant array's value.

public static string checkClassSize(byte[] currentEnrolled)
        {
            for (int i = 0; i < currentEnrolled.Length; i++) { Console.WriteLine(currentEnrolled[i]); }
            return "Nonsense because you didn't define the string";
        }
kplcjl 17 Junior Poster

I DO assume this thread should be marked solved unless the OP is not into my flavor of C++.

My comment about "solved" was directed at kikiritce who is the only one who can mark this thread Solved. It is still marked UnSolved.

kplcjl 17 Junior Poster

My reply was prior to seeing your new post. OK, you know about Math.Sqrt. You didn't define the type of your Sqrt variable. The type you supplied to Sqrt does not match the type it expects. That should be fine, it should automatically convert int to the right type but this is the type of thing that can bite you in the @ss ao you need to know when you are taking the shortcut.

It IS critical you fix your Sqrt variable's type correctly, setting it to int won't cut it. Your logic is missing the variable that caclulates the sum.

Personally, I wouldn't put Console.ReadLine() inside the loop, I would put it right after writing out the sum AFTER the loop has finished.

kplcjl 17 Junior Poster

I'm confused. This is obviously a homework problem. For that, you don't deserve a code answer. You are supposed to produce something like:
Value: 1, Square: 1, Cube: 1, Sqrt: 1
Value: 2, Square: 4, Cube: 8, Sqrt: 1.4142135623731
Value: 3, Square: 9, Cube: 27, Sqrt: 1.73205080756888
Value: 4, Square: 16, Cube: 64, Sqrt: 2
Value: 5, Square: 25, Cube: 125, Sqrt: 2.23606797749979
Value: 6, Square: 36, Cube: 216, Sqrt: 2.44948974278318
Value: 7, Square: 49, Cube: 343, Sqrt: 2.64575131106459
Value: 8, Square: 64, Cube: 512, Sqrt: 2.82842712474619
Value: 9, Square: 81, Cube: 729, Sqrt: 3
Value: 10, Square: 100, Cube: 1000, Sqrt: 3.16227766016838
Value: 11, Square: 121, Cube: 1331, Sqrt: 3.3166247903554
Value: 12, Square: 144, Cube: 1728, Sqrt: 3.46410161513775
Sum of all Sqrt values: 29.2490045916973

I wrote the code to do that in 11 lines. The square and cubes are simple math statements, you just need to know how to calculate them. That's obviously part of your homework. There are equations for finding the N'th root of numbers, but you don't even have to know that fairly advanced mathmatics. The square root is a built-in function of the Math tool. (A built-in part of the system namespace.)

I've probably given you more help than your teacher wanted you to have in order to solve this.

kplcjl 17 Junior Poster

Yes, it is ok. the problem is how to display just one letter "u" or "U"? thank for your time

Interesting that you are answering a quoted phrase that doesn't exist now and his post doesn't show as edited.

Since his replaced text fully answers your question, you should either mark this thread as solved or explain why his answer doesn't solve the solution.

His solution is case insensitive, the way you stated the problem makes it look like you really wanted that, not one that is case sensitive which is the default behaviour. If you do want case sensitive, remove the .ToLower() function.

kplcjl 17 Junior Poster

The term "output screen" is accurate, but a little confusing when you talk about getting input from it. You're getting input from the keyboard in this case, the screen echos what you type because of your programming.

I think you are confusing the visual display with physical attributes. If you type 10 the box routines physically create an 11X11 box of asterisks. (IE A totally square box.) Visually, it looks like a rectangle because characters are set up in a rectangular box where the vertical height is HIGHER than the horizontal width.

I don't know the exact proportions, but it looks like the width is about 80% of the height. That changes per device. You need to change the physical characteristics so the box LOOKS square. Try setting the width = height * 100 / 75; and playing around with the 75 to see if the box consistently looks square when you enter 5 or 80 for the width.

(You'll need to adjust the right lines' starting point with the same width.)

kplcjl 17 Junior Poster

Of course you could have a BitMap put in your console app and save your cube in an image file like png. (Once you've got your Winapp running, most of what you learn there, transfers to here.) Bits are more 1 to 1 in x/y directions. Think 3,4,5 triangles. Depending on the compression your viewer uses 32X32 is about a quarter of an inch more or less square.

kplcjl 17 Junior Poster

And of course the web formatting removed all the blanks I added in the above example.

For webapps, you've got a lot of reading to do. Look up System.Drawing.Drawing2D and look at their examples. That's a whole 'nother can of worms, you can spend a lot of time working on it. Enjoy.

kplcjl 17 Junior Poster

You could start the first line with 5 blanks, use dash - or underscore _ to print the top edge of the cube. (1 short of the cube length followed by |)
Next line 4 blanks, a /,2 short of the box length with spaces, followed by /|.
For the next 3 lines reduce a space at the beginning and add the space between the / and |.
Now for 2 short of the box length's lines put |, 2 short of length spaces, |, 4 spaces, /
Repeat that for 3 lines reducing the number of spaces to / by 1
Finish with dashes for the length.

Here's a not quite the same representative cube. Increase the length of the cube to make it more realistic. (Height 70% of width, + for corners
+-----------+
/ /|
/ / |
/ / |
/ / |
+-----------+ |
| | |
| | /
| | /
| | /
| |/
------------+

kplcjl 17 Junior Poster

I have made some changes that were suggested but still getting errors of

Error 1 'test.Converter.currency': cannot declare instance members in
a static class
Error 2 'converter': cannot declare instance members in a static class

When I suggested using a static class I also said to get rid of the int you weren't using.

private int currency;

is an instance member and the int I suggested you get rid of. (error 1) I forgot to mention that if the class is static everything in it has to be static as well. Things like routines. (error 2)

kplcjl 17 Junior Poster
int[] breakdown = new int[4];
//hint hint. You just defined an array called breakdown that has 4 values that are all 0
int dollarAmount;

Console.Write("Please enter a Dollar amount: ");
dollarAmount = Convert.ToInt32(Console.ReadLine());
// Really, look into TryParse. What if your user says "five dollars"?
//Don't underestimate the stupidity of users

Console.WriteLine("The Dollar Amount Entered Was: {0:c}", dollarAmount);
//well you should be getting the output you expect from the above line. Correct?
Console.WriteLine("Twentys: {0}", breakdown[0]);
// between hint and now, what have you done to change the array's values ? 
//Hmmm, wasn't there something you were supposed to do? Like with the Converter class?

It's your job to think about the process, what you are trying to do, and how you think it should work. It might help to write out comments. Every good coder does.
Write out what you want to accomplish in a comment.
Just before you do something, write out what you are trying to accomplish in a comment.
Do all the comments completely describe everything you want to do?
You might want to put a comment before every line explaining what it is doing and why it is being done. I don't think you wrote the converter routine, it has problems but is still showing more thought about process than you are used to doing. It's OK to be handed code, but if your teacher handed you the code, you need to know what it is doing and why it is …

kplcjl 17 Junior Poster
string command = "xyz";
            char x = command[0];
            //char y = command[4]; compiles but blows up because index out of range.
            //string y = (string) command[0]; won't work. You can't implicitly or explicitly convert char to string
            //char[] y = (char[]) command; won't work. You can't implicitly or explicitly convert string to char[]

Think of a string as an implicit array of single characters, but not quite. It isn't a two way street or even a direct one way street. If you have intellisense it will tell you exactly what it can do as soon as you type "[" in the command. The commented code won't work and tells why as well

kplcjl 17 Junior Poster

Consider making Converter a static class. (Assuming you remove the int I was complaining about.) You don't need an instance because you aren't storing data related to the class in it.

kplcjl 17 Junior Poster

first thing I noticed was

private int currency;
        public void converter(int currency, int[] breakdown, int[] denom)

It's OK, but it is a bad practice to use instance field names as local variables.
If your last denom[] isn't 1, it is possible to create an infinite loop, except that your code would blow up as soon as x overindexed the array.
Considering you never define or use the instance name, drop it from the code or comment on what you plan on doing with it in the future.

converter.converter(dollarAmount, breakdown, denom);

How could this compile when you ask it it convert dollarAmount when you've never declared what that variable is or defined it?
Using the same name for an object and a routine is OK, but tacky.

converter.dollarAmount = Convert.ToInt32(Console.ReadLine());

Converter has never declared a property or field called dollarAmount.
Read in invalid data and your code will blow up if you ever get it to run. Suggest you change this to an int field, declared and defined prior to trying to convert it.

Convert.ToInt32 is a terrible user interfacing method. The user enters non-numeric data, this will blow up. You don't have try/catch blocks set up for this. Check out the function "int.TryParse". Don't need try/catch blocks, it trys returns true if successful or catches and returns false. An out parameter defines the int value.

kplcjl 17 Junior Poster

Listviews are rather dumb. In the help it shows adding an array of text:
...clipped code
The stupid thing works because the default vertical size will cause a rollover at Item 1/col 2. Shift the height and you shift the lists that line up with each other.

I take it back. It's not dumb, it has a misleading property name and a misleading message in help. If the help was a little clearer, it might say
"The MultiColumn property, when true will cause the ListBox to scroll horizontally instead of vertically when the list is longer than the window can show."
The way it is, I too, thought this was a way to format a multicolum object like a DataRow when I first read it. I think a boolian property like "HorizontalScroll" would have a more intuitive meaning to it. No changing it now.

kplcjl 17 Junior Poster

Listviews are rather dumb. In the help it shows adding an array of text:

this.listBox1.Items.AddRange(new object[] {
              "Item 1, column 1",
              "Item 2, column 1",
              "Item 3, column 1",
              "Item 4, column 1",
              "Item 5, column 1",
              "Item 1, column 2",
              "Item 2, column 2",
              "Item 3, column 2"});

The stupid thing works because the default vertical size will cause a rollover at Item 1/col 2. Shift the height and you shift the lists that line up with each other.

kplcjl 17 Junior Poster

In a library file (dll) I know you can modify an existing property and the exe continues running without recompiling.
If you add properties to the dll class and if it isn't critical that the exe knows about them, would the exe continue working without recompiling? Personally, I'll bet not, but I'd like an answer from someone who knows.

kplcjl 17 Junior Poster

This is still flagged as unsolved. Please change the status. (Or explain why it is still unsolved.)

kplcjl 17 Junior Poster

It is good form to mark your post solved if a solution is found. (You should be the only one who can do that.)

kplcjl 17 Junior Poster

Which is what I said in my post way back at the beginning of this thread! Does anyone actually bother to read the replies?

I did. I agreed with you, but it was so blatently obvious, I didn't think it needed comment or reinforcement.

kplcjl 17 Junior Poster

I'd also appreciate it so much if you direct me to an awesome site that teaches C# in easy steps.

Yea, wouldn't that be nice.

kplcjl 17 Junior Poster

It's been too long, don't remember the directives, here are some guesses.
'WebApplication3.HumanCheckerService.HumanCheckerApplication' does not contain a definition for 'RandomNumberGenerator'
Your web service directives need to define this method. (I thought you did without a type)
no extension method 'RandomNumberGenerator' ... type 'WebApplication3.HumanCheckerService.HumanCheckerApplication'
The (not shown) code is trying to access the web service by passing an argument into the class, the only service (I think) you defined is without parameters. Define a service that accepts that type or change your calling app to not pass an argument.

" Error 2 'WebApplication3.HumanCheckerService.HumanCheckerApplication' does not contain a definition for 'HumanChecker' and no extension method 'HumanChecker' accepting a first argument of type 'WebApplication3.HumanCheckerService.HumanCheckerApplication' could be found (are you missing a using directive or an assembly reference?) "
Now it's looking like maybe when you set up the web service you didn't attach the HumanCheckerApplication class to your application. Where is it defined? Are you sure it is attached? "HumanCheckerService.HumanCheckerApplication humanCheck = new HumanCheckerService.HumanCheckerApplication();" is coming out of left field if the class isn't available. How/Why do you expect it to be defined?

kplcjl 17 Junior Poster

Do you know that storing ages is a bad idea, as they change all the time?

Momerath makes a good point, but there are tons of bad design decisions already being made. That's part of learning coding, you make bad decisions, you either later see how bad it is or you know it's bad, but you are just trying to figure out how to get it working at all. I just assumed that you either were in the latter group or you would figure out that maybe there are better ways to do this.

kplcjl 17 Junior Poster

OK, still don't know what your problem is.
Are you connecting to the database successfully? If not, what is the message? How are you connecting?
Is there information in the database?
Have you decided how you want to retrieve information from the Database?
Does it work? (Do you see you are getting the data from the DB?)
How are you trying to put it in the text box?
Are you beginning to see there are several steps involved in getting data from a DB and you haven't answered anything? It could be as simple as, "You haven't bothered to read anything about a text box and you want your answer given to you." It doesn't work that way, first you prove you tried, show what you tried and what doesn't work.
Is the box visible? (Starting to streach

kplcjl 17 Junior Poster

Random comments about code, unrelated to your question:
DataTable kliente; // It is a good practice to declare "private", basically because it visually separates the object as a persisting instance of the class. (You aren't looking for the method wrapping the declaration.)
private DataTable MaakKlientTabel() // either declare the return type void or never reference kliente in the code. The point of this code should be either to exclusively create the kliente object (return void) or to create a Datatable image that matches kliente that could either be used to create the kliente object or a copy of the DataTable elsewhere. The way it is now, if you happened to ask for a copy of the image, you would wipe out the memory of kliente, and your "copy" IS kliente.

If you make it void, in New_Client_Load just execute MaakKlientTabel()

int gesl = Convert.ToInt32(textBox3.Text.Substring(6, 1));
//This would blow up if you put in a non-numeric character in the text box. Use:
int gesl;
if (!int.TryParse(textBox3.Text, out gesl))
{//Put whatever logic needed if the user didn't enter a number into textBox3}

Putting in the code you are attempting to execute is always a good idea, but not if it isn't germain to your main question.

Creating a DB structure in code is extremely difficult in any DB system. You haven't demonstrated that you understand there IS a DB structure in any DB. (Creating a memory copy of the DB structure is …

kplcjl 17 Junior Poster

The point of having databases is to persist data. Why do you want a DB if you don't want to persist data?

Have you thought about just creating an XML file?

When you are creating a DB, before you enter data, you have to create the schema. Before you create the schema, you have to create the DB. In order to do that, you have to have the JET engine create the access file. (I have no idea how to do that. As an exercise, I tried to do that. Never could get it to work.) There isn't anything in your code even attempting to create the connection to the JET engine, so you can work with Access.

kplcjl 17 Junior Poster

By the way, if I am ignorant of csv files, it doesn't prove I am stupid. I am ignorant of a lot of things, just like everyone else on the earth. Obstinately remaining ignorant is a sign of stupidity, but that also doesn't prove anyone is stupid. Being told about a best practice and forgetting about it is regrettable, but isn't stupid. Being told about and expressely violating a best practice for no valid reason is stupid.

My function has a mistake. name is nullable so the where clause should also have had " AND name IS NOT NULL"

kplcjl 17 Junior Poster
@ mr debasis.. Sir, I read & tried this command again, my query is partially solved. thanks!!


@ kplcjl.. thanks a lot for your detailed analysis & help.
firstly.. i mentioned that i need to transfer Coulumn filled with data entries.. that means whole schema + values in that column..
2nd.. How can you presume that I am working on system databases??? better check your guessing strategies.. there are hell lot of csv file available online which can be imported in Sql Server.. i hope you are not ignorant of this thing, coz it would be stupid if you are!!

In the original post you said: "I am having two tables in MS SQL SERVER 2005 in master database." I presumed from this that you were using the master database. Since "master" is a system database in SQL Server, I presumed you were modifying the schema of at least one system database. How silly of me to presume that was true!

With rare exceptions columns do not contain schema.(xml comes to mind and binary or text fields that SQL has no knowledge of schema. I don't know the xml type well enough to know if SQL recognizes schema in it.)

I am again left guessing what you mean. (The following example does alter the schema of a system database, but one of the two special system DBs it is OK to alter.)

USE tempdb
SET ANSI_NULLS ON
SET QUOTED_IDENTIFIER ON
IF (OBJECT_ID('dbo.city') IS NULL) 
BEGIN
	exec …
kplcjl 17 Junior Poster

All the replies to you have been based on reasonable assumptions based on what you said. Because you aren't clear on what you want, you force people to guess. I'm guessing based on your not liking the responses you have gotten.

I'm going to re-write your question and answer it. You say if the question is close to what you really want.

How do I get a column's values from one table into another table when the other table doesn't have the column defined?

(The difference? You are saying the schema of the other table isn't right. Why I think that's what you mean? Neither of the responses you got were acceptable.)

First off, you can't do this in one step. Use ALTER TABLE to add a column to the other table first. If the table has data already in it either this new column must be nullable or you supply a default value that can be overridden.

(You do specify column names in all of your existing queries, don't you? Otherwise, you probably just broke your existing queries.)

Second, you need to plan how you want the data from the one table put into the second table. You have two ways to do this: insert or update. With insert you need to figure out how to supply all the required columns in the table along with the new column's values. With update you need to figure out how you are going to join …

Knvn commented: Nice Attempt +1
kplcjl 17 Junior Poster

This is marked as unsolved. It is your responsibility to post it as solved.

Just wanted to make the point that C# has done a lot of good work to remove SQL insertion but it is possible when dynamic SQL is involved. (After reading what I wrote earlier, I realize that it was wrong. Because of the unbalanced quotes, it wouldn't work as an attack. There still are places where a dynamic SQL command could be attacked.

kplcjl 17 Junior Poster

I am really surprised that you said "UPDATE accounts SET @company WHERE id = @id" works. I'd believe "UPDATE accounts SET company=@company WHERE id = @id"

Now for your @company string -> "junk';truncate table accounts;--"
This used to work as an attack in the old style because the formatting was
CMD = "UPDATE accounts SET company='" + Str + "' WHERE id = " + id.ToString()

The command SQL would see in the new format is
UPDATE accounts SET company='junk'';truncate table accounts;--' WHERE id = 1234

Even though this really is a dynamic query, you are maintaining the relationship of working with a string in SQL being set to a string in your parameter list so a SQL attack can't happen. I wonder what happens if you violate that principle?

create a table accountx with a company field, add a few records where company is not "junk"
Try "UPDATE @accounts SET company=@company WHERE id = @id"

In your @accounts string "accountx' SET company='junk';--"

I'm betting every row in the table is "junk". If it is, then you proved SQL insertion is possible.
If it isn't, I'm going by memory so interactively try:
UPDATE 'accountx' SET company='junk'
If it blows up, then my memory is screwed up. If not, wow, I'm impressed and really surprised with C#.

kplcjl 17 Junior Poster

Oh yea. If your connection account doesn't have authority to create databases, that would explain why the straight dynamic create command doesn't work. Horray, you at least have something set up properly. (Properly set up, your account shouldn't be allowed to do anything BUT call stored procedures and that is because the sproc specifically granted EXEC permission. Hardly anyone properly sets up the security model.)
If you create the stored procedure in an account that does have authority to create DBs, your program would be allowed to create them in the sproc. (With minor exceptions.)

kplcjl 17 Junior Poster

First off, SQL injection is prevented in parameters because the code is formatted to match the parameter's datatype. This is designed to be passed as a parameter in a stored procedure.

So, you pass it @DBName SYSNAME in the parameter. The value can be:
"YouLose;drop database msdb;drop database master"

That can't be a sql injection because a line in the sproc that says
CREATE DATABASE @DBName
WOULD blow up.

IF you are using dynamic SQL, it is YOUR RESPONSIBILITY to prevent a SQL injection attack. The same as if you are building a dynamic SQL command like the other suggestion made.

So, keep your procedure, but in your C# code make sure the data entered is alphanumeric, spaces or known characters like "_" or "-" and the string is no longer than 254 characters. (It should work up to 256, but anyone who wants a DB that long is up to something. Maybe limit it to 60?)

In your sproc code, execute dynamic SQL:
[SQL]
DECLARE @dynCmd NVARCHAR(300) = 'CREATE DATABASE '
IF EXISTS( SELECT * FROM sys.databases WHERE NAME = @DBName)
RAISERROR('The DB name you picked already exists', 16, 1)
ELSE
EXEC (@dynCmd)
[/SQL]

Don't check in C# and my first example wouldn't cause SQL injection, but there are still ways you could end up with missing DBs if your account is allowed to do so.