data from multiple tables

Please support our VB.NET advertiser: Intel Parallel Studio Home
Reply

Join Date: Jan 2008
Posts: 7
Reputation: Kartikey is an unknown quantity at this point 
Solved Threads: 0
Kartikey Kartikey is offline Offline
Newbie Poster

data from multiple tables

 
0
  #1
Jan 14th, 2008
hello sir ,



Q:-How to display data in datagrid from multiple tables in SQL server 2000 and vb.net 2003
its very imp for my project

i have tried with following code
Pl tell me the correct way to do it

tables i am using are

TABLES COLUMN CONSTRAINTS COLUMN NAMES

t_candidates reg_no primary key , f_name ,email_id
t_additioinalinfo reg_no foreign key , cat_id foreign key
t_category cat_id primary key category (this column ontains actual category values)

t_result reg_no foreign key, rc_name ,salary


Dim ds As DataSet
ds = New DataSet
Dim objshortlistedresume As New frmshortlisted
Dim str As String
Try
str = "select reg_no,category,rc_name from t_candidates" & _
"Join t_result on t_candidates.reg_no=t_result.reg_no" & _
"join t_additionalinfo on t_category.cat_id =t_additionalinfo.cat_id" & _
"join t_additionalinfo on t_result.reg_no=t_additionalinfo.reg_no"

Catch exp As SqlException
MsgBox(exp.Message, MsgBoxStyle.Critical, "SQL error")
Catch exp As Exception
MsgBox(exp.Message, MsgBoxStyle.Critical, "General error")
End Try



Dim mydataadapter As SqlDataAdapter = New SqlDataAdapter(strshortlisted, myconn)

mydataadapter.SelectCommand = New SqlCommand
mydataadapter.SelectCommand.Connection = myconn
mydataadapter.SelectCommand.CommandText = str
mydataadapter.SelectCommand.CommandType = CommandType.Text

Try
myconn.Open()

mydataadapter.SelectCommand.ExecuteNonQuery()
mydataadapter.Fill(ds, "t_candidates")
myconn.Close()
' dv = New DataView(ds.Tables("t_candidates"))

objshortlistedresume.dg_shortlisted.DataSource = ds
objshortlistedresume.dg_shortlisted.DataMember = "t_candidates"

Catch exp As SqlException
MsgBox(exp.Message, MsgBoxStyle.Critical, "SQL error")
Catch exp As Exception
MsgBox(exp.Message, MsgBoxStyle.Critical, "General error")
End Try

objshortlistedresume.Show()
Me.Hide()
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 2,641
Reputation: Jx_Man is a glorious beacon of light Jx_Man is a glorious beacon of light Jx_Man is a glorious beacon of light Jx_Man is a glorious beacon of light Jx_Man is a glorious beacon of light Jx_Man is a glorious beacon of light 
Solved Threads: 245
Jx_Man's Avatar
Jx_Man Jx_Man is offline Offline
Posting Maven

Re: data from multiple tables

 
0
  #2
Jan 14th, 2008
maybe on select statment for join tables
Last edited by Jx_Man; Jan 14th, 2008 at 6:06 am.
Never tried = Never Know
So, Please do something before post your thread.
* PM Asking will be ignored *
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 2,641
Reputation: Jx_Man is a glorious beacon of light Jx_Man is a glorious beacon of light Jx_Man is a glorious beacon of light Jx_Man is a glorious beacon of light Jx_Man is a glorious beacon of light Jx_Man is a glorious beacon of light 
Solved Threads: 245
Jx_Man's Avatar
Jx_Man Jx_Man is offline Offline
Posting Maven

Re: data from multiple tables

 
1
  #3
Jan 14th, 2008
this is my code when read data from multiple tables, in my code just for two tables, you can change to three or more tables.
  1. Private Sub Show_Datagrid()
  2. Dim cmdUser As New SqlCommand
  3. Dim daUser As New SqlDataAdapter
  4. Dim dsUser As New DataSet
  5. Dim dtUser As New DataTable
  6.  
  7. conn = GetConnect()
  8. Try
  9. cmdUser = conn.CreateCommand
  10. cmdUser.CommandText = "SELECT a.Id_User as 'User Id', a.Password , b.Id_Role as 'Role Id', b.Status FROM USERS a join ROLE b on (a.Id_Role=b.Id_Role)"
  11. daUser.SelectCommand = cmdUser
  12. daUser.Fill(dsUser, "User")
  13. dgUser.DataSource = dsUser
  14. dgUser.DataMember = "User"
  15. dgUser.ReadOnly = True
  16. Catch ex As Exception
  17. MsgBox("Error: " & ex.Source & ": " & ex.Message, MsgBoxStyle.OKOnly, "Error Connection!!")
  18. End Try
  19. End Sub
Never tried = Never Know
So, Please do something before post your thread.
* PM Asking will be ignored *
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 13
Reputation: chan_lemo is an unknown quantity at this point 
Solved Threads: 1
chan_lemo chan_lemo is offline Offline
Newbie Poster

Re: data from multiple tables

 
0
  #4
Oct 21st, 2008
data from multiple table using dataset

http://vb.net-informations.com/datas...-sqlserver.htm

lemo
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC