Wrox Programmer Forums
|
VB.NET 2002/2003 Basics For coders who are new to Visual Basic, working in .NET versions 2002 or 2003 (1.0 and 1.1).
Welcome to the p2p.wrox.com Forums.

You are currently viewing the VB.NET 2002/2003 Basics 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 April 19th, 2005, 07:34 AM
Registered User
 
Join Date: Apr 2005
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default Bound ComboBox Database Query

Hi,
Firstly I should clarify that I am very new to VB.net (I have never done any coding at all before), so thank you in advance for any assitance.
I have designed a form and bound a combobox (using the DayTimePicker control) it's bound to a Date field in an SQL Table.

Once the date is chosen, and the other data on screen changed and written to the database, I would like to arrange the code so when that same date is chosen, that the rest of the data on the screen auto populates to the entries from the database.
I didn't realise how difficult this would be to explain actually, so please forgive me if it isn't making sense.
Ultimately, I think the question is, Can I get my combo box to query my database, see if that date already exists, and populate the textboxes, etc that relate to that record? and allow me to either edit, or just view the data?

Thanks in advance again.

D
 
Old April 19th, 2005, 08:27 AM
Friend of Wrox
 
Join Date: Oct 2003
Posts: 326
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to Santhi Send a message via MSN to Santhi
Default

You cant autopopulate the data.You have to write coding in the code-behind file.In the Combobox control SelectedIndexChanged event ,check in the database for the selected date.If data exists,query the database and set the values to the textboxes you have declared.If data not exists,leave the textboxes blank.

 
Old April 19th, 2005, 08:43 AM
Registered User
 
Join Date: Apr 2005
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I see, i didnt expect it to be so arduous, makes sense though.
Thanks for your help :)
D
 
Old April 20th, 2005, 12:22 AM
Registered User
 
Join Date: Apr 2005
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Actually, with your advice in mind I went back to my code, and stared at the screen blankly, googled for hours, and decided that I might find the answer in a bottle of beer. Alas, I am back, none the wiser. The question has now become:
My ComboBox (lets call it DatePicker) is selected, I have used the ValueChanged Event.
If my text box is called "txtWeatherThatDay", my database is called "WeatherMan", the table is called "TableOfWeather", what comman would generically be used to find the "DatePicker" value in my database and then let me say that the database value of "txtWeatherThatDay" = the textbox value of "txtWeatherThatDay"?

I hope that is clear.
Thanks again.
 
Old April 20th, 2005, 01:52 AM
Friend of Wrox
 
Join Date: Oct 2003
Posts: 326
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to Santhi Send a message via MSN to Santhi
Default

What are the fields present in TableofWeather?I dont know what is the structure of your database.If you are taking weather info from the database,surely date field might be present in that table.Use that to match the DatePicker value.

 
Old April 20th, 2005, 02:11 AM
Registered User
 
Join Date: Apr 2005
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

That is exactly what I am asking .
The Fields in there do comtain the date I am hoping to select from the combo box.
The question ultimately is what is the command line that would be used to tell the combo box to actually look at the database and find if that date selected matches one in the database?





Similar Threads
Thread Thread Starter Forum Replies Last Post
Formatting TextBox bound to a database column Raby Visual Basic 2005 Basics 1 September 6th, 2006 07:47 PM
Data type mismatch -- Combo box bound to database jamenijamjam Beginning VB 6 2 September 1st, 2006 08:36 PM
Blank row in Data Bound ComboBox joblot VB How-To 1 May 5th, 2004 01:33 PM
Data Bound ComboBox joblot VB How-To 0 May 5th, 2004 12:18 AM





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