Can someone point me in right direction for database questions..

Im trying to get my head around the database/sql features of vb 2005 express.  Ive followed the beginners tutorials and managed to get a database up and running on a form but i would like to know if the following scenario is possible and how to go about it.

Lets say I have 2 tables.. one for Customers and one for Invoices..  the primary key "CustomerID" in customer table and foreign key CustomerID in the Invoice table.

Ok, so ive made a form thats for making a new invoice and I would like the field that references the CustomerID to actually show a dropdown box with the Customers names from the Customer table.  How do i go about doing this   is there a tutorial that goes a bit more into the database side of vb like this

thanks in advance


Answer this question

Can someone point me in right direction for database questions..

  • Farzin Tarat

    Yes, with the use of DataBinding. Set the dataSource of the comboBox to the Customers table. Set DisplayMember to the CustomersName and set ValueMember to CustomersId.

    Good luck.

  • TianYu

    Quick question:

    The behaviour of the latest release of the Visual Express (VB) appears to have changed.

    It does not seem possible to databind the datasource of a combobox to a dataset table, but know one has to specifically select a data table member. 

    Can't get it to work...  only shows the first table entry but the drop down box is empty.



  • Bogdan Grigorescu

    string queryString =
                            "SELECT CustomerId FROM dbo.Customers;";



                using (SqlConnection connection = new SqlConnection(yourConnectionString))
                {
                    SqlCommand command = new SqlCommand(
                        queryString, connection);
                    connection.Open();
                    SqlDataReader reader = command.ExecuteReader();
                    try
                    {
                        while (reader.Read())
                        {
                            this.ComboCustomers.Items.Add(reader[0].ToString());
                        }
                    }
                    finally
                    {
                        // Always call Close when done reading.
                        reader.Close();
                    }


                }

  • JYanez

    Thanks for the reply.

    I was wondering if its possible using object settings/properties without code

  • Can someone point me in right direction for database questions..