Solved

How is this insert statment writen?

Posted on 2009-05-04
11
193 Views
Last Modified: 2012-05-06
I want to add i table Customer
where my customerid = "MYCOMPANY"
and set the columb bVisible to checked (it is a box in the table)

INSERT INTO Customers (bVisible) VALUES(True) WHERE (CustomerID) = MYCOMPANY

is that correct?
0
Comment
Question by:Mickeys
  • 6
  • 4
11 Comments
 
LVL 61

Expert Comment

by:mbizup
ID: 24296611
Are you sure you do not need to UPDATE an existing record?
UPDATE Customers
SET bVisible = True WHERE CustomerID = 'MYCOMPANY'

INSERT adds a new record, Also, if CustomerID is text, you need quotes as shown.
0
 
LVL 61

Expert Comment

by:mbizup
ID: 24296638
The WHERE clause is what made me think you were working with existing records (UPDATE) versus adding new ones (INSERT)
0
 

Author Comment

by:Mickeys
ID: 24296677
ah update it is.

so is this correct?
"UPDATE Customers SET bVisible=true WHERE (CustomerID) ='" + RemoveTextBox.Text + "'";
0
 
LVL 61

Expert Comment

by:mbizup
ID: 24296704
That looks good... Give it a whirl.
0
 

Author Comment

by:Mickeys
ID: 24296812
hmm it runs the query but the checkbox keeps beeing empty
0
Get up to 2TB FREE CLOUD per backup license!

An exclusive Black Friday offer just for Expert Exchange audience! Buy any of our top-rated backup solutions & get up to 2TB free cloud per system! Perform local & cloud backup in the same step, and restore instantly—anytime, anywhere. Grab this deal now before it disappears!

 

Author Comment

by:Mickeys
ID: 24296855
if i only run

UPDATE Customers SET bVisible=true
all gets set

but if I add where nothing happens.
0
 
LVL 40

Expert Comment

by:Sharath
ID: 24297188
Do you have your CustomerId in this box, RemoveTextBox.Text ?
give a try.
"UPDATE Customers SET bVisible=true WHERE CustomerID ='" + RemoveTextBox.Text + "'";
0
 
LVL 61

Accepted Solution

by:
mbizup earned 500 total points
ID: 24297483
Can you post the full line of code?

"UPDATE Customers SET bVisible=true WHERE (CustomerID) ='" + RemoveTextBox.Text + "'";

Why is there a semicolon outside of the parentheses?


Give this a shot:

"UPDATE Customers SET bVisible=true WHERE (CustomerID) ='" + RemoveTextBox.Text + "';"

Then check the actual value held in RemoveTextBox.Text.

If it is not updating the records, it sounds like you do not have any records where CustomerID matches RemoveTextBox.Text.

Finally, please verify whether CustomerID is text or numeric in your database.
0
 
LVL 61

Expert Comment

by:mbizup
ID: 24297510
Also, is your user interface written in VB or Access VBA?
0
 

Author Comment

by:Mickeys
ID: 24298330
I found the error. I used RemoveTextBox..........when I should have used another named textbox. I had copy the text so the clue was from mbizup:  :-)

0
 
LVL 61

Expert Comment

by:mbizup
ID: 24298603
Glad you got it sorted!  :)
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

CCModeler offers a way to enter basic information like entities, attributes and relationships and export them as yEd or erviz diagram. It also can import existing Access or SQL Server tables with relationships.
Shadow IT is coming out of the shadows as more businesses are choosing cloud-based applications. It is now a multi-cloud world for most organizations. Simultaneously, most businesses have yet to consolidate with one cloud provider or define an offic…
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now