Home All Groups Group Topic Archive Search About

How to pull the data out from two table and bind to repeater

Author
27 Mar 2005 2:37 PM
chng yeekhoon via DotNetMonster.com
HI All,

Can somebody help what's wrong with my SQL Query statement when i want to
create a join table query. It suppose work perfectly fine, but why it cant
work. The error that the ASP.Net throw out is "Object reference not set to
an instance of an object. " and "System.NullReferenceException: Object
reference not set to an instance of an object." at the line
dtrViewApplication.Close()

I have two table which are Job (JobID, JobTitle) and Application(JobID,
DateApplied, jobseekerID). I want both table field to be joined and display
by using Repeater.

Pls refer to the below for the source code.

Dim jobProvider As OleDbConnection

Dim cmdSelect As OleDbCommand

Dim dtrViewApplication As OleDbDataReader

Dim strSelect As String

     jobProvider = New OleDbConnection
("PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA Source=C:\Inetpub\wwwroot\JobSeeker\
JobProvider.mdb")

     strSelect = "select JobID, DateApplied, Job.JobTitle from
Application, Job where Application.JobID = Job.JobID And " & _

                     " jobSeekerID=@jobSeekerID"



     cmdSelect = New OleDbCommand(strSelect, jobProvider)

     cmdSelect.Parameters.Add("@LoginName", "JS12345")

Try

     jobProvider.Open()

     dtrViewApplication = cmdSelect.ExecuteReader

     rptApplication.DataSource = dtrViewApplication

     rptApplication.DataBind()

Catch ex As Exception

     Label1.Text = ex.Message & vbCrLf & ex.Source & vbCrLf &
ex.StackTrace & vbCrLf & ex.TargetSite.Name

Finally

     dtrViewApplication.Close()

     jobProvider.Close()

End Try

Thanks in advance

--
Message posted via http://www.dotnetmonster.com

Author
28 Mar 2005 5:06 PM
Elton Wang
Change your sql query to

SELECT Job.JobID, Application.DateApplied, Job.JobTitle
FROM Job JOIN Application ON Job.JobID = Application.JobID
WHERE Application.jobseekerID = @jobSeekerID

HTH

Elton Wang
elton_w***@hotmail.com

>-----Original Message-----
>HI All,
>
>Can somebody help what's wrong with my SQL Query
statement when i want to
>create a join table query. It suppose work perfectly
fine, but why it cant
>work. The error that the ASP.Net throw out is "Object
reference not set to
>an instance of an object. "
and "System.NullReferenceException: Object
>reference not set to an instance of an object." at the
line
>dtrViewApplication.Close()
>
>I have two table which are Job (JobID, JobTitle) and
Application(JobID,
>DateApplied, jobseekerID). I want both table field to be
joined and display
>by using Repeater.
>
>Pls refer to the below for the source code.
>
>Dim jobProvider As OleDbConnection
>
>Dim cmdSelect As OleDbCommand
>
>Dim dtrViewApplication As OleDbDataReader
>
>Dim strSelect As String
>
>     jobProvider = New OleDbConnection
>("PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA
Source=C:\Inetpub\wwwroot\JobSeeker\
>JobProvider.mdb")
>
>     strSelect = "select JobID, DateApplied, Job.JobTitle
from
>Application, Job where Application.JobID = Job.JobID
And " & _
Show quoteHide quote
>
>                     " jobSeekerID=@jobSeekerID"
>
>
>
>     cmdSelect = New OleDbCommand(strSelect, jobProvider)
>
>     cmdSelect.Parameters.Add("@LoginName", "JS12345")
>
>Try
>
>     jobProvider.Open()
>
>     dtrViewApplication = cmdSelect.ExecuteReader
>
>     rptApplication.DataSource = dtrViewApplication
>
>     rptApplication.DataBind()
>
>Catch ex As Exception
>
>     Label1.Text = ex.Message & vbCrLf & ex.Source &
vbCrLf &
>ex.StackTrace & vbCrLf & ex.TargetSite.Name
>
>Finally
>
>     dtrViewApplication.Close()
>
>     jobProvider.Close()
>
>End Try
>
>Thanks in advance
>
>--
>Message posted via http://www.dotnetmonster.com
>.
>