Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > SQL Server > SQL Server 2000 > SQL Server 2000
Password Reminder
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
SQL Server 2000 General discussion of Microsoft SQL Server -- for topics that don't fit in one of the more specific SQL Server forums. version 2000 only. There's a new forum for SQL Server 2005.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Server 2000 section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old December 15th, 2006, 02:04 PM
Registered User
Join Date: Dec 2006
Location: london, , United Kingdom.
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default using sql commands C#

Hi peeps. I realise this is a possible cross over of categories but i need help anyhow!

Ok i am becoming pretty clued in with the SQL statements now. So i don't talk loads of rubbish and confuse people firstly, here's my statement:

string updateup = "UPDATE ContactList SET Address = '" +comboBoxDepartmentUpdate.Text+ "' " +
", FullName = '" +txtNameUpdate.Text+ "' "+
", DirectLine = '" +txtDirectUpdate.Text+ "' "+
", Mobile = '" +txtMobileUpdate.Text+ "' "+

"WHERE Address = '" +comboBoxDepartment.Text+ "' "+
"AND FullName = '"+comboBoxName.Text+ "'";

Now the statement works fine. But:

1. Can someone please tell my why i DO NOT need parameters for this to work when updating?
2. What i want is for people to be able to press a button and it will update all the fields BUT ONLY IF they have entered something into them. So i tried this:

if(comboBoxDepartment.SelectedIndex >= 0)
cmdUpdate.Parameters.Add("@Address",SqlDbType.Char ,255,"Address").Value = comboBoxDepartmentUpdate.Text;

if(txtNameUpdate.TextLength > 0)
cmdUpdate.Parameters.Add("@FullName",SqlDbType.Cha r,255,"FullName").Value = txtNameUpdate.Text;

if(txtDirectUpdate.TextLength > 0)
cmdUpdate.Parameters.Add("@DirectLine",SqlDbType.C har,255,"DirectLine").Value = txtDirectUpdate.Text;

if(txtMobileUpdate.TextLength > 0)
cmdUpdate.Parameters.Add("@Mobile",SqlDbType.Char, 255,"Mobile").Value = txtMobileUpdate.Text;

i was hoping that this would only release the parameters if people had selected or entered some data.

However i found out that you don't actually need to define the parameters for some strange reason so the update statement just updates everything including BLANK fields!!!

now i know i could do switch-case but that would mean creating at least 14 different statements, i know there must be an easier way to say, if the field is blank then don't update???

Hopefully it's clear as to what i'm getting at please ask for more info if it's needed!

Thanks a lot

When **** becomes valuable the poor will be born without *******s.
Reply With Quote

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
sql commands dr BOOK: Beginning Ruby on Rails 1 April 27th, 2007 12:22 PM
runtime sqldatasource sql commands- HELP iori ASP.NET 2.0 Basics 0 August 14th, 2006 05:38 PM
How to exeucte a file containing sql commands Hari_Word VB How-To 2 September 30th, 2004 06:00 AM
Dynamically Changing SQL Commands? avantjer BOOK: Professional Crystal Reports for VS.NET 2 May 18th, 2004 11:29 PM
Using 2 SQL commands attipa Classic ASP Databases 2 September 20th, 2003 05:23 PM

All times are GMT -4. The time now is 07:27 AM.

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.