Wrox Programmer Forums
|
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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old December 15th, 2006, 02:04 PM
Registered User
 
Join Date: Dec 2006
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
Nath

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





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





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