Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Visual Basic > VB 6 Visual Basic 6 > Pro VB Databases
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
Pro VB Databases Advanced-level VB coding questions specific to using VB with databases. Beginning-level questions or issues not specific to database use will be redirected to other forums.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Pro VB Databases 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
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old March 30th, 2006, 11:22 AM
Registered User
 
Join Date: Mar 2006
Location: , , .
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default Search / Add data in a ComboBox

Hi,

I’m using VB 2005 and SQL Server 2005.

I have a ComboBox which displays data from a table. It displays colours, like red, green and blue.

What I would like to do, is if the user puts a colour in the ComboBox which doesn’t exist in the table, it asks the user if they want to add this colour to the table.

So if the user keys black and black is not a choice in the ComboBox, it adds black to the table.

Does anyone have a sample app showing this working ?

Thanks so much. Any help much appreciated.

Thanks,
Reply With Quote
  #2 (permalink)  
Old May 4th, 2006, 07:51 PM
Registered User
 
Join Date: May 2006
Location: Bremerton, WA, USA.
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default

What I have always done is in the AfterUpdate event handler for that combo box, I put a piece of code that inserts the color into the table, (assuming there is a unique key on color in the table.)
Literally you use an INSERT statement in SQL. The best way to do this is to make an Insert stored procedure, and pass the new color as a parameter to that stored procedure. This puts database code in the database where it belongs, instead of coding SQL statements in the form control event handlers. Be sure to handle any errors raised by SQL server in your code, just in case the insert fails.

~ Shaun
Reply With Quote
Reply


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
Search by User_Name with combobox Grafixx01 Access 2 May 25th, 2007 08:27 PM
Search / Add data in a ComboBox Sudoku Visual Basic 2005 Basics 0 March 30th, 2006 11:21 AM
How to add search functionality to unbounded form? method Access VBA 4 June 24th, 2005 06:40 AM
add same data in diff table / search yylee Access VBA 8 April 13th, 2004 02:39 AM
Add ComboBox into DataGrid(WinForm) shiju VS.NET 2002/2003 1 November 1st, 2003 11:50 PM



All times are GMT -4. The time now is 08:16 AM.


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