Friday, March 9, 2012

problem joining table is SQL query

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.sqlmonster.comA NullReferenceException means that your code is attempting to use an object
that has not yet been initialized. This may be dtrViewApplication since
it's neither declared nor instantiated in your code snippet. I suggest you
check to ensure dtrViewApplication is instantiated before setting the
DataSource property.
Also, this is a SQL Server forum but it appears you are using Access. The
problem seems to be related more to your ASP.NET code rather than data
access. You'll probably get more help in an ASP.NET forum.
--
Hope this helps.
Dan Guzman
SQL Server MVP
"chng yeekhoon via SQLMonster.com" <forum@.SQLMonster.com> wrote in message
news:f1dd26950b84414b87be4ebfe886a5ac@.SQLMonster.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.sqlmonster.com

No comments:

Post a Comment