kplcjl 17 Junior Poster

One of the things that has always amazed me about most stories of time traveling machines is that you always end up at the same location where you started. (Except for the more "realistic" spaceships that travel in time.)
The earth at its equator is spinning at around a 1000 miles per hour, everyone on earth is traveling around 4000 miles per hour around the sun. We're moving even faster than that in our galaxy. And galaxies are pulling away from each other at nearly the speed of light. Yet, we have people go outside the century old ruins of a castle, and poof, the castle is 100 yards away and a few years old.

kplcjl 17 Junior Poster

@Grimjack, your novel had two separate points of view, because two people can't have the same point of view. In fact everyone experiences changing points of view as they go through life. Since I didn't read it, for all I know, that is two points of view from the same person.
Can the person who time travels ever get back to where they started? (Since a person died in the past, if you go back in the past to save them, there is no reason to go back in the past because you saved them, so how could you get back to where you did go back, since you wouldn't need to go back in the first place.) They've got some great movies like that already, so that wasn't my idea. (I think.)

kplcjl 17 Junior Poster

It's been 45 years or so since I read flatland. My memory is fuzzy, so if you want to challenge me, I won't argue. Flatlanders never looked up or down because that dimension didn't exist to them. They were all circular in shape, their buildings were rectangular lines. They were visited by a 3-dimentional sphere which caused great consternation because it suddenly appeared as a point and got to be a bigger and bigger circle (person) in their world, and then it got smaller and smaller until it just disappeared.
It never explained how these circular people moved. I wondered if they had pathways, how you got on and off a path. (Doors like buildings had?)
Time makes a wonderful fourth dimension. We appear from nothing, we get bigger and bigger, then smaller and smaller until we disappear. So we are fourth dimensional creatures visiting a three dimensional world. We just aren’t true fourth dimensional creatures because we don’t control movement through all 4 dimensions, we just use one to change where we are in the other three dimensions. So flatlanders really were 3 dimensional creatures.

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

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

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

can another way through which UI thread remain running

You will never, ever, see a form respond to a form change while the form's thread is active. The form thread MUST be idle, for changes to be returned to the form's thread to act on them. The timer solution works because it is a delegate running independently of your form thread. (There is a bug in the given logic "if (++i > 199)" will stop at 199 just like your loop.) If you want the user to be unable to do anything until the count is finished, then use his first solution. If you want another way, this will work, but I bet you like it less than the timer solution.

1. Create a routine to handle updating of your label from the passed information.
2. Create a small class that has a delegate routine. A looping routine.
3. Assign your form routine to your delegate.
4. start the looping routine in a new thread.
5. In the loop call the delegate and then Sleep. Forget the Refresh, you don't need it.

PS. I have a combo box that picks between 10, 5, 1, 0.1, 0.5, 0.05, 0.01, and 0.0 convert that to an integer a 1000 times bigger and sleeps for that time. (I sleep for a maximum of 500 and increment up to the set time when it is bigger than that. When you sleep for 10 seconds, it is agonizing to …

kplcjl 17 Junior Poster

FYI You have public static bool stopped = false;
being set to true by an instance. Note that if you have multiple instances, this would be set to true in one instance where another instance could still be running. You might want to set that as an instance get property and a private bool so no-one else can muck with it. If you have multiple instances then you could wait for the final move to finish before you exit.

kplcjl 17 Junior Poster

If your problem is solved you should mark it solved.

An alternate is to put an if statement in your move loop.

if (!Stopping) File.Move(s.FullName, TargetFile);

It would finish the last move of files and then just loop through everything without doing additional work and then leave. Since you have a try block, before the loop you could declare:

int zero = 0;

and after the move and still in the loop

if (Stopping) zero = 1/zero; //Intentionally aborting the loop

Not sure what stopping a thread in the middle of a move would do. (Purists would have you throw an exception instead of intentionally blowing up.)

kplcjl 17 Junior Poster

You an use System.IO.File.GetCreationTime(filename) to get when a particular file was created. Compare that to today's date and delete as necessary. You can then open a file with append access via a StreamWriter to write to a file. If the file exists, it will merely be appended to. If not, it will be created. Sample below.

string filename = @"C:\yourfilepath_and_name.txt";
        DateTime fileDate = File.GetCreationTime(filename);

        if (fileDate.Date < DateTime.Now.Date)
        {
            File.Delete(filename);
        }

        StreamWriter writer = new StreamWriter(filename, true); // opens file for appending
        writer.WriteLine("write to the file");

        // finish processing, then close and dispose of object
        writer.Close();
        writer.Dispose();

Compile your code to an executable, create a scheduled task in your operating system, and off you go.

Wouldn't "if (fileDate < DateTime.Now.Date)" work as well?
Or "if (File.GetCreationTime(filename) < DateTime.Now.Date)"?

kplcjl 17 Junior Poster

Are you declaring a string and adding string variables to your list or are you running the function in the add? If you are working with strings, make sure what is passed is a string.
If it is receiving an object in the key that it can't figure out the order of, I'm surprised it even allows you to add it.
try casting it as string and add that.

kplcjl 17 Junior Poster

Come to think of it, the override would probably work, it probably resides in Win32, not Forms. You can't depend on the Form closing event processor, because it doesn't exist. Note that the loop you wanted to put in can't be put in. but a regular loop should continue working if you override the closing event.

kplcjl 17 Junior Poster

It's probabbly because you have a console app and Message is part of System.Windows.Forms eg not included in a console app by default.

Even if you add the assembly reference I don't think the WndProc will work unless you have a form.

Sorry, didn't read your code carefully. You should blow up because you are trying to override code that doesn't exist. If it doesn't after you put in the using statement, you may have the event process needed to do what you want. If it does, this definitely won't work. Putting in a request for user input may trigger a "code is not responding" error asking you if you want force shut-down and may lock you out of your app.

kplcjl 17 Junior Poster

I tried to use it, but getting an error

Error 1 The type or namespace name 'Message' could not be found (are you missing a using directive or an assembly reference?)

my application code is given here

...        }
}

...

That message tells you exactly what is wrong. The complete object address is: System.Messaging.Message Put using System.Messaging; at the beginning of your code or spell it out.

kplcjl 17 Junior Poster

Great! Now how do i get the area and the perimeter and are from clsRectangle to the area and perimeter boxes?

I assume you mean text boxes. There is a string property called "Text" that you can set. When you do, you can set that value to the returned property or function to display it and that shows up on your text box.

That's assuming the box is visable and has a contrasting forecolor so you can see the text. (Default) Since this is intended as a display box make it read only.

kplcjl 17 Junior Poster

I don't know if there are indexing routines, but you can set your starting position at 0. while it is less than the length of the string and the character at that position is blank go to the next starting position
set your ending length to 0 and while the length + position character are not blank and not past the end of the string you increment the length by 1. That identifies the length and position of the next word that you insert into a string array and increment the array by one.
Repeat that process using the new starting position until all the words are added to the array. Initalize a string with the last word in the array, from the next to last word to the beginning add a blank and that word to the string. This will not retain multiple blanks in the reversed string.

kplcjl 17 Junior Poster

1. It is poor design to have a character field value added to a table that is contained in another table instead of referencing the table (IE WindowID)
2. It is poor design to use (char) for fields that don't have a fixed number of characters
3. It is poor design to not use an order by statement when you aren't using selection criteria and only taking a piece of the information.
That said:

--initial test tables
SET NOCOUNT ON
DECLARE @tblUsers table (UserID int primary key, FirstName varchar(20), LastName varchar(20), BirthDate smalldatetime)
DECLARE @tblDueVisits table (UserID int, DueDate smalldatetime, WindowName varchar(20) null)
DECLARE @tblWindows table (WindowID int identity, WindowName varchar(20) null)
--initialize tables
declare @dtnow smalldatetime, @id int,@txt varchar(3),@rw int 
select @dtnow='20091105',@id=1
WHILE @id < 100
BEGIN
	set @txt=@id
	insert into @tblUsers values (@id, 'First' + @txt, 'LastName' + @txt, dateadd(year,-@id,@dtnow))
	insert into @tblWindows values ('WindowName'+@txt)
	select @id=@id*2,@rw=@@identity
	WHILE @rw > 0
	BEGIN
		insert into @tblDueVisits values (@id, dateadd(day,@id*@rw,@dtnow),null)
		set @rw=@rw-1
	END
END
set nocount off
--SELECT * FROM @tblUsers
--SELECT * FROM @tblWindows
--SELECT * FROM @tblDueVisits
SET NOCOUNT ON
-- Process requirement
SET @id=16
DECLARE @tbl1 table (ID1 int IDENTITY, DueDate smalldatetime)
DECLARE @tbl2 table (ID2 int IDENTITY, WindowName varchar(20) null)
INSERT INTO @tbl1 SELECT DueDate FROM @tblDueVisits WHERE UserID=@id
SELECT @rw=@@ROWCOUNT
INSERT INTO @tbl2 SELECT TOP (@rw) WindowName from @tblWindows
Update @tblDueVisits set WindowName=c.WindowName
from @tblDueVisits a
join @tbl1 b on a.DueDate=b.DueDate and UserID=@id
join @tbl2 c on ID1=ID2
select * from …
kplcjl 17 Junior Poster

Again, I sincerely hope you find it is IMPOSSIBLE to put a DB on my SQL server if I happen to link to your web site. There are enough security holes to drive a mack truck through without adding this one to it.
I'm kind of conflicted because I usually don't want someone to fail in their endevours, but I definitely hope you fail.

kplcjl 17 Junior Poster

Sorry, I didn't explain what I did.
"@dtyr=YEAR(GETDATE())" automatically casts the INT result of the YEAR() function into a 4 character string. The string format "YYYYMMDD" is globally recognized as a valid date format, no matter what format your local date setting uses. (IE "DD/MM/YYYY", or "MM/DD/YYYY", etc.) so "@dt1=@dtyr + '0101'" is the first day of the first month of this year at midnight. "DATEADD(YEAR,1,@dt1)" should explain itself, however if you use that in the BETWEEN statement it would include next year's data that started at January 1 midnight so "@dt2=DATEADD(MINUTE,-1,@dt2)" excludes next year's data. If you use DATETIME instead you would need to subtract 3 milliseconds. (If you did that and your comparison field was smalldatetime it would still round up to next year in the comparison.)

PS You should subscribe to SQLServerCentral, you get interesting articles e-mailed to you periodically. They just had an extensive article about this very issue.

kplcjl 17 Junior Poster

What sknake said, however he didn't give an example. You need to provide constants in the where clause, so calculate constants. If you are only recording current datetimes in the table you only need to find "WHERE SalesDate >= @dt1". If you are recording future dates as well or if you want to go to some year in the past use "WHERE SalesDate BETWEEN @dt1 AND @dt2".

DECLARE @dt1 SMALLDATETIME, @dt2 SMALLDATETIME, @dtyr CHAR(4)
SELECT @dtyr=YEAR(GETDATE()),@dt1=@dtyr + '0101',@dt2=DATEADD(YEAR,1,@dt1),@dt2=DATEADD(MINUTE,-1,@dt2)
kplcjl 17 Junior Poster

@Thirusha correction, you can do DB connectivity with AJAX which is essentially JavaScript ;)

Sorry, I forgot about AJAX. It isn't just JavaScript. It is a combination of JavaScript and XMLA. One of the key phrases in the AJAX tutorial is "AJAX uses the XMLHttpRequest object". This is, in effect your cgi link I was talking about. The intent in the tutorial was to connect to a server that had your DB interface already built.
I assumed that the request was to create a database on the client since JavaScript is and remains client-side code only. I can't think of any valid reason for creating a database on the server-side. If he is dead-set on creating a DB on the client side, I suppose it is possible using AJAX, I still say it is impossible using JavaScript. You would need an unnamed SQL Server object running on the client, the person running the web page would need admin rights on SQL, you would connect using the local IP address, verify the DB doesn't exist on the client server and create it.
I sincerely hope and pray that using AJAX to create a DB on my server is impossible as well. I hate to think what a set of malware could do to me being able to connect to me, as me, just by setting up a web page. I hate what they can do now that requires a constant update of sentry software.

kplcjl 17 Junior Poster

Hello,

I want to create database on SQL Server using Javascript and HTML. User will input following data. Server Name, Database name, File Sizes. When I will click "Submit" button database should be created on Selected server with entered name. I am using Client side HTML and Javascript.
we need to create database according to some standards thus we are preparing graphical user interface.
Quick response will be appreciated.

Thanks, Rahul

Impossible. Javascript is not designed to do work on another server, it is client side software that only runs on the client. Both HTML and JavaScript can post to a cgi which could do something like this. If the server name entered also hosts the cgi, Javascript could post the instructions to the server name's cgi and let it do the work. That or the client hosts the cgi and the user account has access to the server name.