473,395 Members | 2,192 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

question with data binding (noobie question)

lets say i have 1 table called Inventory and another table called itemType

Inventory
-itemID -PK
-Desc
-itemID- FK

itemType
-ItemID - PK with relation to inventory.itemID - FK
-ItemName

I have a dataset with these tables and a bindingsource with the inventory table
I created a form to display both data

the question is, how do i bind data with itemType to a combo box so it allows me to view the item type for each item and save the changes. I can already save the changes for the inventory, but im having problems with displaying my itemTypeComboBox properly, im not sure what to put in the
Data Bound Items> Data source, Display member, Value Member, Selected Item and Selected Value of the comboBox

Im using Visual Studio 2008 and SQL 2005

any suggestion would be greatly appreciated, im very new with visual basic so please be easy on me... thanks ^_^
Nov 2 '08 #1
3 1225
TamusJRoyce
110 100+
From what little experience I have (and that's very little. I'm a c++ programmer, mostly), once you bind your class to the table, the object you bind it to will automatically be changed as you change the table.

Try not directly manipulating the datasource/bounditem from the table, but instead directly use the object you set bound to that table.

As an example, you can find what has been selected by comparing "If Table.SelectedRow.BoundItem Is TheClassThatWasBound.AnArray(elementIndex) Then" manipulate TheClassthatWasBound.AnArray(elementIndex).

Poorly worded, but the idea is to only work on the object that is bound (as the source), and never on the Tables DataSource/BoundItem.

But I've never directly bound data to a combo box, so maybe there is a graphical way to bind the same object to both your table and your combo-box.

Anyone else have any ideas?
Nov 2 '08 #2
From what little experience I have (and that's very little. I'm a c++ programmer, mostly), once you bind your class to the table, the object you bind it to will automatically be changed as you change the table.

Try not directly manipulating the datasource/bounditem from the table, but instead directly use the object you set bound to that table.

As an example, you can find what has been selected by comparing "If Table.SelectedRow.BoundItem Is TheClassThatWasBound.AnArray(elementIndex) Then" manipulate TheClassthatWasBound.AnArray(elementIndex).

Poorly worded, but the idea is to only work on the object that is bound (as the source), and never on the Tables DataSource/BoundItem.

But I've never directly bound data to a combo box, so maybe there is a graphical way to bind the same object to both your table and your combo-box.

Anyone else have any ideas?
Thanks, I'm still trying to understand databases. I found some videos on msdn that teaches how to bind data to an object graphically. it would be great to understand how to bind data through coding but im not quite there yet ^_^. But you're right, the data does change automatically when I change the table... im still trying to figure out how to prevent that. ^^

Thanks for the advice
Nov 3 '08 #3
OuTCasT
374 256MB
Thanks, I'm still trying to understand databases. I found some videos on msdn that teaches how to bind data to an object graphically. it would be great to understand how to bind data through coding but im not quite there yet ^_^. But you're right, the data does change automatically when I change the table... im still trying to figure out how to prevent that. ^^

Thanks for the advice
This is how i bind items dynamically.

Create ur connectionstring
Create ur SqlDataAdapter
and fill is with your SqlCommand

Expand|Select|Wrap|Line Numbers
  1. Dim sqlCon As SqlConnection = New SqlConnection([connectionString])
  2.  
  3. 'Commands and adapter for the Employee masterfile
  4.     Dim sqlEmployeeCommand As SqlCommand
  5.     Dim sqlEmployeeAdapter As SqlDataAdapter
  6.     Dim sqlEmployeeDataTable As DataTable
  7.  
  8. 'Currency Managers for Commands above
  9.     Dim sqlEmployeeManager As CurrencyManager
  10.  
  11. sqlEmployeeCommand = New SqlCommand([SELECT STATEMENT)sqlConnection)
  12.         sqlEmployeeAdapter = New SqlDataAdapter(sqlEmployeeCommand)
  13.         sqlEmployeeDataTable = New DataTable
  14.         sqlEmployeeAdapter.Fill(sqlEmployeeDataTable)
  15.  
  16. label1.databindings.add("text",sqlEmployeeDataTable, "[ColumnName]", true)
and u bind it so on etc.
Remember to create a currency manager to be able to navigate through the records and create one if you want to save.

Expand|Select|Wrap|Line Numbers
  1. sqlEmployeeManager = DirectCast(Me.BindingContext(sqlEmployeeDataTable), CurrencyManager)

If you want to save this is what you do.


Expand|Select|Wrap|Line Numbers
  1. sqlEmployeeManager.EndCurrentEdit()
  2. sqlConnection.Open()
  3.  
  4.  Dim sqlEmployeeUpdate As New SqlCommandBuilder(sqlEmployeeAdapter)
  5. Try
  6.        sqlEmployeeAdapter.Update(sqlEmployeeDataTable)
  7.  
  8. Catch sqlExc As SqlException
  9.        MsgBox(sqlExc)
  10. End Try
  11.  
  12. sqlConnection.Close()
Nov 4 '08 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: Aristotelis E. Charalampakis | last post by:
Hi all, this is a newbie question :-) I was wondering if there was a way to use the switch statement in a manner that each case statement includes more that a simple value. i.e.: switch (...
1
by: JD Kronicz | last post by:
Hi .. I have an issue I have been beating my head against the wall on for some time. I am trying to use late binding for MS graph so that my end users don't have to worry about having the right...
6
by: Mike | last post by:
Lets just say my app is done HOO HOO. Now, I'm accessing the database via a web service and one thing i noticed that my app is running real slow. When I first started working on the app is ran...
1
by: Bruce | last post by:
Hi, there, I meet a problem about comboBox binding. -------------------- Database: Northwind Tables: 1) Products 2) Categories I create a form (named "form1") to edit the record from...
2
by: JohnR | last post by:
I have a question on bindingcontext, bindings, and controlbindingscollection. I understand the very basic idea, and I think I should be able to do this, but I'm not sure how. First problem: I...
3
by: Lou | last post by:
Question: I can't seem to get file.exists(filename) to return true when I search using wildcards, and I know there's a file in that dir with that extension. here's the path dim yesno as...
7
by: Ryan | last post by:
I'm in the process of learning more about building my ASP.NET website to use my SQL datastore and am a bit confused about how ADO.NET works with ASP.NET. This Microsoft article implies that using...
4
by: sanou | last post by:
Hi No doubt this question, or a similar version of it, has been asked before. But, I was looking around the forums and i couldn't find anything. I'm using VC++ to create a simple calculator...
1
by: nick777 | last post by:
Hope the Community can bear with me as I muddle with the vocabulary since I am not really sure if I am going about this the correct way. My question is as follows: If I had some sample data in...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.