UPDATE or not to UPDATE....

This may seem really trivial (which in case should be easy to answer) otherwise bear with me!

if i didnt want my UPDATE query to run say based on the fact that some text boxes were empty hw do i tell the command object to stop writintg the Data to the database table e.g. in my application if 3 textboxes are not empty then the UPDATE query will execute and will update the fields in the database. but if the textboxes are empty then how do i not execute the query??
see my code below for further info:

private void
Submit_DatabaseDates()
{
if (Txt_Cal1StDate.Text == "" || Txt_Cal2EnDate.Text == "" || Txt_StTime.Text == "" ||
Txt_EndTime.Text == "")
{
What do i write here!!!!
}
else
{
int evID = Convert.ToInt32(Request["EID"]);
TotChanged = TotChanged + 1;

string insertCmd = "INSERT into EventDateChange (EventID, NewStartDate, NewEndDate, NewStartTime,
NewEndTime, PrevStartDate, PrevEndDate, DaySlippage, Reason, TotalChanged) VALUES (@evID, " + "
@NewStDate, @NewEnDate, @NewStTime, @NewEnTime, @PrevStDate, @PrevEnDate, @DaySlippage,
@Reason, @TotalChanged)";

myCmd = new SqlCommand(insertCmd, mycn);
myCmd.Parameters.Add(new SqlParameter("@evID", SqlDbType.Int, 4));
myCmd.Parameters["@evID"].Value = evID;
myCmd.Parameters.Add(
new SqlParameter("@NewStDate", SqlDbType.SmallDateTime, 4));
myCmd.Parameters["@NewStDate"].Value = PopUpCal1.SelectedDate.ToShortDateString();
myCmd.Parameters.Add(
new SqlParameter("@NewEnDate", SqlDbType.SmallDateTime, 4));
myCmd.Parameters["@NewEnDate"].Value = PopUpCal2.SelectedDate.ToShortDateString();
myCmd.Parameters.Add(
new SqlParameter("@NewStTime", SqlDbType.VarChar, 10));
try
{
myCmd.ExecuteNonQuery();
}
catch (SqlException s)
{
}
finally
{
myCmd.Connection.Close();
}
}
}

0
mrssm
4/7/2006 3:31:22 PM
asp.net.getting-started 91979 articles. 3 followers. Follow

4 Replies
825 Views

Similar Articles

[PageSpeed] 51

return;
Regards

Dave
0
DMW
4/7/2006 4:32:33 PM

Here's another option that's probably a better practice.

Instead of this:

if (Txt_Cal1StDate.Text == "" || Txt_Cal2EnDate.Text == "" || Txt_StTime.Text == "" ||
Txt_EndTime.Text == "")
{
What do i write here!!!!
}
else
{

Do This:

if !(Txt_Cal1StDate.Text == "" || Txt_Cal2EnDate.Text == "" || Txt_StTime.Text == "" ||
Txt_EndTime.Text == "")
{

Or This :   

if (Txt_Cal1StDate.Text == "" || Txt_Cal2EnDate.Text == "" || Txt_StTime.Text == "" ||
Txt_EndTime.Text == "") = False
{


Chris Berg, MCAD
My Blog

0
cubeberg
4/7/2006 4:46:15 PM
Hello,

If you to want to display some informative error(eg. Enter some text in ....) on scrren. Write code for that in it. Actually if you put RequireFieldValidatior on these textboxes. Then there is no need to write if ..else
block.

If you've more submit button on one page. Then you can also able to define group for particular submit button and 3 textboxes.

Regards.

Kuldeep Deokule

MCSD.NET
Blog: http://dkuldeep.blogspot.com

This posting is provided "AS IS" with no warranties, and confers no rights.
0
deokule2003
4/7/2006 4:51:03 PM

A better practice would be to use RequiredFieldValidators. And you write your code to UPDATE in this block

if (Page.IsValid) {

   // Write your update code here.

}

You need to write code for not to update. If you have to hold errors, use try catch and display the error in a label!

HTH


Mark post(s) as "Answer" that helped you

Electronic Screw
Website||Blog||Dub@i.net
0
e_screw
4/7/2006 5:49:06 PM
Reply:

Similar Artilces:

updates, updates, updates, NO MORE!
Name: Andreas Email: unbekanntatjokerdotms Product: Firefox Summary: updates, updates, updates, NO MORE! Comments: Hi ! if you want to develop a fine webbrowser, maybe you nee a new management. To release a new buggy version every two weeks is not very professional. Test your software before the release and let the user download a stable browser. this update-orgy since 2.0.0 used me to use Opera instead of FF. We haved use FF in our Company, but we can't deploy a new version every week to +200 Windows-clients, so in our company we've decided to return to IE, ...

Updates Updates Updates
I was a big fan of Firefox.. Now, I don't even like to use it. Seems like every time I start it up I have to update some addin OR the browser itself. And unfortunately the update nag messages are always presented when I start a browsing session. I find this annoying because, typically, when I open a web browser all I want to do is go to a web page. Not update the browser. I can agree that staying current with the latest version could give the best, fastest, safest web experience. But that point becomes mute when I start off every other browsing session with a new update. And mos...

Updates, updates and more updates
Name: pirhan Email: pirhan_chanathotmaildotcom Product: Firefox Summary: Updates, updates and more updates Comments: Hello, Normally I use Safari, but my iBook is out of commission for a while. So, I am forced to use a PC to which I would much rather use Firefox than Internet Exploder. However, as much I enjoy not using a Microsoft product, and use a product that works decently, I am severely annoyed about the constant updates I am put through. In the last two days, I had to wait for Firefox to install updates before I could browse and now, I'm alerted that there'...

updates, updates, updates
Name: hans jensen Email: hansjensen44_athotmaildotcom Product: Firefox Summary: updates, updates, updates Comments: why is it everytime i go online firefox has new updates, 3 -4 times every day, its never ending..........whats all the problems??? please email me and let me know, ty,.........Hans Jensen Browser Details: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.2) Gecko/20070219 Firefox/2.0.0.2 ...

updates, updates, updates
Holy Crap, Batman! You'd think I was running Windows XP and it's patch Tuesday. So far this week - new kernel (2.6.27.10), 2 new browsers (Opera 9.63 and Firefox 3.05) and a new plugin (Flash 10.0.156.3). I'm about ready to try one od the BSD's! vince wrote: > Holy Crap, Batman! You'd think I was running Windows XP and it's patch > Tuesday. > > So far this week - new kernel (2.6.27.10), 2 new browsers (Opera 9.63 > and Firefox 3.05) and a new plugin (Flash 10.0.156.3). I'm about ready > to try one od the BSD's! I take ...

Updates Updates Updates #3
Name: Product: Firefox Summary: Updates Updates Updates Comments: Seems like every time I open the program there is a wait period while some new arcane update gets installed. I have enjoyed and advocated firefox for a good while, but the update thing is really starting to bug me. Doubtless I could simply change the settings to accept the updates or not notify me or something similar - but I CAN'T BE ASSED. I'd have to consider this for more than 30 seconds and as we've already seen I CAN'T BE ASSED. Please make this less annoying in return for which I promis...

Update Update
Name: John Oswell Email: serviceatwinntecdotcom Product: Firefox Summary: Update Update - endless updates Comments: I think it's great you update the product but I'm starting to think this product is more prone to attack and instability by the number of updates i get inflicted with. Quite honestly on the Windows platform you're going to need to convince me that the Firefox browser is "better" than IE8 - my default browser (ff right now) I'm probably going to revert - endless intrusive updates for Firefox is getting very tiring. At least MS (I'm ...

Updates updates updates #2
Name: Product: Firefox Summary: Updates updates updates Comments: I love Firefox, but it seems EVERY day there is some sort of updates to download before it will open. You need to figure out a way Firefox can open when asked to do so and update in the background and apply the updates on the next restart. Browser Details: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.1.3) Gecko/20090824 Firefox/3.5.3 (.NET CLR 3.5.30729) From URL: http://hendrix.mozilla.org/ Note to readers: Hendrix gives no expectation of a response to this feedback but if you wish to provide on...

updates,updates, updates,etc.
Name: Product: Firefox Summary: updates,updates, updates,etc. Comments: I am so fed up with all these gd updates I COULD SCREAM! Why can't you get it right and stay with it for a while. Between you guys and MSFT you drive me nuts. Browser Details: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.1) Gecko/2008070208 Firefox/3.0.1 From URL: http://hendrix.mozilla.org/ Note to readers: Hendrix gives no expectation of a response to this feedback but if you wish to provide one you must BCC (not CC) the sender for them to see it. ...

Update not updating
Name: Willaim Brasuell Email: williamatbrasuelldotcom Product: Firefox Summary: Update not updating Comments: I get a message to update Firefox and start the process. After letting it run for an hour it just keeps saying it's downloading. Having tried four times I think there is a problem here. Regards, Bill Brasuell Browser Details: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.3) Gecko/20070309 Firefox/2.0.0.4 ...

Update not updating
I'm using Web Matrix and the Update code wizard. I have an Access db with a table 'Users'. This contains a Username (primary key) and a password. If I use:- "UPDATE [Users] SET [Password]=@Password WHERE ([Users].[User] = @user)" the update does not work and no errors are reported. If I use:- "UPDATE [Users] SET [Password]=@Password WHERE ([Users].[User] = ""barry"")" the update works!!!. I've spent hours trying to resolve this to no avail. Could this be a bug in oledb and if so does anyone have a work around? Best frustra...

Update update
Gang... Everything for the forthcoming SSL Certificate Fingerprinting system is finished and ready for pre-release deployment. But today the site has been -- and still is -- unusually busy. And I need to bring the server down briefly to update the master resident "ne.dll" which is where all this code lives. And doing that, boots everyone off, cancels all underway downloads, aborts ShieldsUP! runs, etc. So I want to wait a few hours until things have calmed down, and slowed, down a bit. -- ________________________________________________________________ Steve...

Updates and more updates and more...
Name: M Product: Firefox Summary: Updates and more updates and more... Comments: what's the point of this one exactly? Browser Details: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.11) Gecko/20101012 Firefox/3.6.11 ( .NET CLR 3.5.30729) From URL: http://hendrix.mozilla.org/ Note to readers: Hendrix gives no expectation of a response to this feedback but if you wish to provide one you must BCC (not CC) the sender for them to see it. ...

Why does update not update ?
Name: T. Strickland Email: shortsportatsbcglobaldotnet Product: Firefox Summary: Why does update not update ? Comments: I check to see if there are any updates but it says none are available but once in a while a update will just appear and say to update to 2.0.0.4 . could this be some kind of scam trying to gain access to my computer? If this is a good update then why doesn't the update do it automatically when I click on it ? Please Inform Tilmon Strickland Browser Details: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.0.12) Gecko/20070508 Firefox/1.5.0...

An Update Update ...
Folks, Just off the phone with Mark again. It seems that the points I was making during my afternoon of "debate" with Mark were echoed by the one other person involved in the early (very early) testing of Spambo. As a result one more *VERY* cool feature will soon be added to Spambo: You'll be able to pop-up a listview of all recent eMail which has passed through Spambo -- and sort it any way you like -- where every item will have a "Spam checkbox" showing Spambo's current classification for that piece of eMail. Thus ... all you'll need t...

Web resources about - UPDATE or not to UPDATE.... - asp.net.getting-started

Saturday Night Live Weekend Update Thursday - Wikipedia, the free encyclopedia
Saturday Night Live Weekend Update Thursday is an American limited-run series broadcast on NBC . It is a political satire news show spin-off ...

Gizmodo.com Updates
Nobody should have to use a pay phone , natural disaster or no natural disaster. So if your gadgets are out of juice after Sandy, here’s a tiny ...

Lifehacker.com Updates
By Whitson Gordon Ever run into a situation where you have multiple wireless networks available, but one is clearly better than the other? WiFi ...

Facebook Messenger For Android Update Includes Conversation Shortcuts
Facebook released an update to its Android Messenger application that incorporates the group -creation and message forwarding features in last ...

(Update: it’s back) Tasker has been pulled from the Play Store
Update, November 18: Tasker has been reinstated in the Play Store. A Google spokesperson told Android Police that Google 'worked very closely ...

Evernote updates Penultimate handwriting app for iPad Pro and Apple Pencil
... have an Apple Pencil to go with it? Do you still use Penultimate even after Evernote apparently ruined it for many users with a radical update ...

Site Update: Theme Update finally finished, SSL issues, mobile site is back!
Folks, The theme update is complete and most issues from that are fixed. The mobile site is back, and SSL is close to fixed. That means tomorrow ...

***Live Updates*** Sin City Showdown: GOP Candidates Debate in Vegas
The last GOP presidential debate of 2015 tonight is the first since the Paris and San Bernardino terror attacks. The CNN debate in Las Vegas, ...

How to handle Windows 10 updates
Confused about how updates work in Windows 10 ? Join the club. In this latest version of its operating system, Microsoft has transformed what ...

Book Update
... like dealing with technical debt . Having written today’s post, I am feeling better about the prospect already. Stay tuned for another update ...

Resources last updated: 12/16/2015 6:46:52 PM