|
Change the existing columns to not null, and set the 'Default value' to 0
When you add the new columns ensure you set the default value and not null for them as well.
If you have knowledge, let others light their candles at it.
Margaret Fuller (1810 - 1850)
www.JacksonSoft.co.uk
|
|
|
|
|
CREATE TABLE Table1
(
Name varchar(50),
Payment1 int NOT NULL DEFAULT (0),
Payment2 int NOT NULL DEFAULT (0)
)
|
|
|
|
|
I have to add entries of column "Payment1" & "Payment2" Values, so that I can get a total payment and write the sum in another column "Total Pay".
How to Add these two columns using UPDATE? Is there any other way to update theese two columns and write the sum in another column "Total Pay" ?
|
|
|
|
|
ALTER TABLE Table1 ADD TotalPayment int;
UPDATE Table1 SET TotalPayment = Payment1 + Payment2;
Although, this is a bad practice since it violates principles of normalization
|
|
|
|
|
Hi,
I am adding two columns in "payments" table in database. Column A & B. These two are added and updated in Column "Total Payment". The code I wrote is below, its not updating the sum of A & B in column "Total Payment":
cmd = New SqlCommand("Select * FROM payments", con)
If con.State = ConnectionState.Closed Then con.Open()
myDA = New SqlDataAdapter(cmd)
Dim myDataFinalPaySet As New DataSet()
myDA.Fill(myDataFinalPaySet, "payments")
Dim TotalPaymentValue As Double
Dim TaxablePayment As Double
For Each dr As DataRow In myDataFinalPaySet.Tables(0).Rows
Dim ValA As Double = dr("A")
Dim ValB As Double = dr("B")
TotalPaymentValue = ValA + ValB
If con.State = ConnectionState.Closed Then con.Open()
cmd = New SqlCommand("UPDATE payments SET [Total Payment]= '" & TotalPaymentValue & "'", con)
cmd.ExecuteNonQuery()
cmd = New SqlCommand("Select * FROM payments", con)
myDA = New SqlDataAdapter(cmd)
myDA.Fill(myDataFinalPaySet, "payments")
DataGridPayment.Update()
con.Close()
Next
Can Someone help me onthis?
|
|
|
|
|
Use IsNull on the second column when adding.
Payment1 + Isnull(Payment2,0)
This belongs in the general database forum.
|
|
|
|
|
I have to add entries of column "Payment1" & "Payment2" Values, so that I can get a total payment and write the sum in another column "Total Pay".
How to Add these two columns using UPDATE command? Is there any other way to add these two columns and write their sum in another column "Total Pay" ?
|
|
|
|
|
You need to read BOL and get some idea what you are doing. This is a very basic problem that is exampled throughout the doco.
Update TableName Set TotalPay = Payment1 + IsNull(Payment2,0)
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Hi,
I have an array, x = {10,20,30,"",""). I want the length of this array with non-empty fields, i.e. 3 instead of 5. How to get this in VB?
thanks
|
|
|
|
|
Guess you would have to loop through the array keeping a count of non-empty elements.
|
|
|
|
|
You can write a query in LINQ to filter the array;
Sub Main()
Dim myItems As Object() = {10, 20, 30, "", ""}
Dim myNonEmptyItems = _
From n In myItems _
Where (n.GetType().ToString() <> "System.String") _
Select n
For Each item In myNonEmptyItems
Console.WriteLine("Item: " & item.ToString())
Next
Console.ReadKey()
End Sub Enjoy
I are Troll
|
|
|
|
|
I would like to create a small app to synchronize/backup various groups of files or folders between a flashdrive, home pc and work pc.
Any comments to ensure good speed and reliability regarding the following would be appreciated:
1) To determine which files have changed,
<pre>
Dim di As New DirectoryInfo(Path)
Dim files As FileSystemInfo() = di.GetFiles
Dim fi As FileInfo
'Loop through files and see when last modified, and add to a datatable
For Each fi In files
dr = dtFiles.NewRow
dr.Item(0) = diNext.Name
dr.Item(1) = dr.Item(0) = diNext.LastWriteTime
dtFiles.Rows.Add(dr)
Next
</pre>
Is this OK, or would it be better to check CRC of the files to find the ones that have changed?
I was thinking more along the lines of determining which is the NEWEST file, and then making the sync Bi-Directional though
2) Once I have found the files that are newer, then use:
<pre>System.IO.File.Copy("Sourcefile", "DestinationFile")</pre>
To verify file copied correctly, maybe just put above in a Try... Catch...
Or should I check CRC or something to see if copied correctly?
3) If anyone has done something similar, are there any pitfalls or things I should watch out for?
Tks.
|
|
|
|
|
2). You can use File.Copy the copy the files over, wrapped in a Try/Catch block. You don't have to check the file contents yourself since the O/S takes care of that for you. Since File.Copy is a blocking call, any errors encountered will throw an exception you can catch.
3) Yeah, but I didn't write my own system to do this. I used the MS Sync Framework[^].
|
|
|
|
|
Hi,
I have been searching google for the answer but can't seem to get anywhere.
I have a small program that asks the user for a registration key, they type in the key lets say its "password" the term "password" is then checked on a .txt file in the debug folder and if it is correct they can then install the program on to the hardrive.
This worked brillinat on vb.net however it doesn't work on cd-rw disc.
I WOULD LIKE TO KEEP SOME SECURITY ON THIS PROGRAM that is why i am planing on using CD-RW
i was oringally having the .txt file so that the contents of that .txt file was deleted. is there anyway that the whole file could be dleted or would that still upset the cd-rw???
there must be away round this!?
Dan
|
|
|
|
|
Surely you're overlooking the gigantic flaw that your clients all have rewritable cd-rom drives, what do you do if a client purchases your program and his cd-rom drive does not support writing to cd's?
|
|
|
|
|
I have a checker on form load to see if the disc is in a cd-rom drive if it is, it displays a message saying you cannot install the prgram and then closes the program
|
|
|
|
|
You misunderstood me, I have a CD-ROM drive that is not writable, but is readable. I can have your CD with installation files which passes all your checks, but your program will not be able to write to the CD-ROM drive, causing whatever types of errors.
|
|
|
|
|
Yeah the code i have got should recognise that your CD-ROM drive is only readable and as a result dispay the message saying that you cannot install the software.
I haven't fully tested the software so you may be right however the checks seem to be doing the right thing.
|
|
|
|
|
All i am really aiming to do is to delete 1 FILE from a CD-RW once the installation is taking place (when button install is pressed)
and surely if they have a cd-rom drive when they try and press install when that code is run that would surely crash it (ha ha ha)
anybody got any ideas of how to delete password.txt on the CD-RW???
thanks in advanced
Dan
|
|
|
|
|
offroaderdan wrote: anybody got any ideas of how to delete password.txt on the CD-RW???
No problem[^].
Luc Pattyn
I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages
|
|
|
|
|
anybody SENSIBLE got any ideas of how to delete password.txt on the CD_RW
|
|
|
|
|
Noone does this for very good reason. Using your method, you're destroying the installation media. If they have to reinstall the app for any reason, they're screwed. They have to come begging back to you for another CD. Customers will just not bother with that.
Forget it. Copy protection is just a pipe dream.
|
|
|
|
|
That is the whole point of the disc! I want it like that, if they need a new disc then they can come back to me, it is like only goining to be sold in the village, it not going to be a WORLD WIDE PROGRAM, its going to be a local one!
|
|
|
|
|
Ok then Dave if u made an application which u spent a fair amount of ime on lets say 6 months would u just pput it on a disc and perhaps u were selling the disc for £5. Due to the fact that your basically saying that copy protection is a load of rubbish as soon as one person gets hold of it they'll copy it and distrubute it, and when you try and sell it to people surprisingly enough they've already got it.
Im not trying to argue with you but how would you try and stop people from getting your software or do you give it out to people for free?
|
|
|
|
|
Couldn't someone just copy your CD before running any applications on it? Literally copy, make an ISO, whatever before your application removes the cdkey?
|
|
|
|