Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Visual Basic > VB 6 Visual Basic 6 > Pro VB Databases
|
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 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 March 30th, 2006, 11:22 AM
Registered User
 
Join Date: Mar 2006
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,
 
Old May 4th, 2006, 07:51 PM
Registered User
 
Join Date: May 2006
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





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





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