5 Replies - 296 Views - Last Post: 14 April 2013 - 01:01 AM Rate Topic: -----

#1 vks.gautam1  Icon User is offline

  • D.I.C Regular

Reputation: 17
  • View blog
  • Posts: 317
  • Joined: 21-March 08

Data from different tables which are not interelated

Posted 10 April 2013 - 07:38 AM

I wanna display data in combo boxes in my form..all tables have no common columns so i need to write different queries for every table..like we have commit to insert data ..is there any other simple way to get things done..
This is i write for one table..now there are four remaining tables to data extract.
 q = "select category_name from item_category_master"
            cn = New SqlConnection("server=.\sqlexpress;initial catalog=pharmacy;integrated security=sspi")
            cn.Open()
            ad = New SqlDataAdapter(q, cn)
            ds = New DataSet
            ad.Fill(ds, "item_category_master")
            cmbCategory.DisplayMember = "Category_Name"
            cmbCategory.DataSource = ds.Tables(0)



Is This A Good Question/Topic? 0
  • +

Replies To: Data from different tables which are not interelated

#2 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 8364
  • View blog
  • Posts: 31,073
  • Joined: 12-June 08

Re: Data from different tables which are not interelated

Posted 10 April 2013 - 07:44 AM

If all four tables worth of data are not going in the same control, then yes.. you'll need four different queries. No common column and no common GUI to dump them means everything is separate.
Was This Post Helpful? 0
  • +
  • -

#3 Luc001  Icon User is offline

  • D.I.C Addict

Reputation: 84
  • View blog
  • Posts: 617
  • Joined: 04-May 09

Re: Data from different tables which are not interelated

Posted 10 April 2013 - 07:45 AM

Hi,

You can find some information here.

Hope it helps
Was This Post Helpful? 0
  • +
  • -

#4 vks.gautam1  Icon User is offline

  • D.I.C Regular

Reputation: 17
  • View blog
  • Posts: 317
  • Joined: 21-March 08

Re: Data from different tables which are not interelated

Posted 10 April 2013 - 08:16 AM

Well i got this from net..but im getting problem..

Error -- "Object Reference not set to an instance of an object"
Try
            q = "select category_name from item_category_master"
            q1 = "select generic_name from item_generic_master"
            cn = New SqlConnection("server=.\sqlexpress;initial catalog=pharmacy;integrated security=sspi")
            cn.Open()
            cmd = New SqlCommand(q, cn)
            ad.SelectCommand = cmd
            ad.Fill(ds, "item_category_master")
            ad.SelectCommand.CommandText = q1
            ad.Fill(ds, "item_generic_master")
            ComboBox1.DisplayMember = "category_name"
            ComboBox1.DataSource = ds.Tables(0)
            ComboBox2.DisplayMember = "generic_name"
            ComboBox2.DataSource = ds.Tables(1)
            ad.Dispose()
            cn.Close()
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try


This post has been edited by vks.gautam1: 10 April 2013 - 08:17 AM

Was This Post Helpful? 0
  • +
  • -

#5 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 8364
  • View blog
  • Posts: 31,073
  • Joined: 12-June 08

Re: Data from different tables which are not interelated

Posted 10 April 2013 - 08:29 AM

Typically it's great to tell us what line that is on.
Was This Post Helpful? 0
  • +
  • -

#6 vks.gautam1  Icon User is offline

  • D.I.C Regular

Reputation: 17
  • View blog
  • Posts: 317
  • Joined: 21-March 08

Re: Data from different tables which are not interelated

Posted 14 April 2013 - 01:01 AM

well i got this way..so i would like to share with you guys...
selecting data from different tables
 
cn = New SqlConnection(My.Settings.PharmacyConnectionString)
            cn.Open()
            ad = New SqlDataAdapter("select category_name from item_category_master;select generic_name from item_generic_master;select group_name from item_group_master;select unit_name from item_unit_master;select rack_name from item_location_master;select * from item_master", cn)
            ds = New DataSet
            ad.Fill(ds, "item_category_master")
            cmbCategory.DisplayMember = "Category_Name"
            cmbCategory.DataSource = ds.Tables(0)

            cmbGeneric.DisplayMember = "generic_name"
            cmbGeneric.DataSource = ds.Tables(1)

            cmbGroup.DisplayMember = "group_name"
            cmbGroup.DataSource = ds.Tables(2)

            cmbUnit.DisplayMember = "unit_name"
            cmbUnit.DataSource = ds.Tables(3)

            cmbItemLocation.DisplayMember = "rack_name"
            cmbItemLocation.DataSource = ds.Tables(4)


Was This Post Helpful? 0
  • +
  • -

Page 1 of 1