Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > .NET > .NET 1.0 and Visual Studio.NET > VS.NET 2002/2003
Password Reminder
Register
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
VS.NET 2002/2003 Discussions about the Visual Studio.NET programming environment, the 2002 (1.0) and 2003 (1.1). ** Please don't post code questions here ** For issues specific to a particular language in .NET, please see the other forum categories.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the VS.NET 2002/2003 section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old May 20th, 2005, 09:33 PM
Registered User
 
Join Date: May 2005
Location: , , .
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default Object variable or With block variable not set

URL: http://develop.fauapps.fau.edu/jewis...searchNEW.aspx

Why do I get this error?
Object variable or With block variable not set

Private Sub SBIND()
        '*
        'Code for Oracle 9i
        '*
        Dim MyConnection As System.Data.OracleClient.OracleConnection
        Dim MyCommand As System.Data.OracleClient.OracleDataAdapter
        Dim StudentSelectCMD As System.Data.OracleClient.OracleCommand
        Dim sql_students As String
        Dim valueForsql_student As String

        If Name.Text = "" Then
            Response.Redirect("myFAUsearchNEW.aspx")
        Else
            If rb2.Checked = "True" Then

                'VBScript Replace function to allow faculty names with apostrophes.
                'valueForsql_student = UCase(Replace(Request.Form("Name"), "'", "''"))
                valueForsql_student = Replace(Request.Form("Name"), "'", "''")

                'VBscript Replace function to allow student names with apostrophes.
                'valueForsql_facstaff = Replace(Request.Form("Name"), "'", "''")

                'Original SQL befor Oracle change
                'sql_facstaff = "select Fsname As Name,Title,Dept As Department,BldgRoom,Phone,Email from DB2AS.facstaff WHERE FSNAME LIKE '" & valueForsql_facstaff & "%' order by FSNAME"
                sql_students = "select StudentName As Student_Name,Email from ZZDIRID.STUDIR WHERE StudentName LIKE '" & valueForsql_student & "%' order by StudentName"


                Panel1.Visible = "true"
                Panel2.Visible = "false"
                'label2.Text = MySQL
                Panel3.Visible = "true"
                Panel4.Visible = "false"
                'Panel5.Visible = "true"
                'Panel6.Visible = "true"

                '*
                'Code for Oracle 9i
                '*
                'MyConnection = new System.Data.OracleClient.OracleConnection
                'MyConnection.ConnectionString = "user id=system;Password=manager9i;data source=myoradb_s221n120;persist security info=False"
                MyConnection = New OracleConnection(ConfigurationSettings.AppSettings ("connectStudent"))

                '*
                'Code for Oracle 9i
                '*
                'Modification for Oracle Connection
                StudentSelectCMD = New System.Data.OracleClient.OracleCommand
                StudentSelectCMD.CommandText = sql_students
                StudentSelectCMD.Connection = MyConnection

                MyCommand = New System.Data.OracleClient.OracleDataAdapter
                MyCommand.SelectCommand = StudentSelectCMD

                'Dim DS As DataSet
                'open database connection
                MyConnection.Open()
                'Dim DS As New DataSet

                'DS = New DataSet
                Dim DS As DataSet = New DataSet("MyStuff")
                MyCommand.Fill(DS)

                Dim lblMessage

                'Check to display datagrid if results are returned by query
                If DS.Tables(0).Rows.Count > 0 Then
                    dgStudents.Visible = "true"
                    'lblMessage.Text = ""


                    'close database connection
                    MyConnection.Close()

                    '*
                    'Code for Oracle 9i
                    '*
                    dgStudents.DataSource = DS.Tables(0).DefaultView
                    dgStudents.DataBind()

                End If

                'Check to remove datagrid if no results are returned by query
                If DS.Tables(0).Rows.Count <= 0 Then
                    dgStudents.Visible = "false"
                    lblMessage.Text = "<b><i>Sorry - no record exist with the last name of: </i></b>" & Name.Text
                End If
            End If
        End If
    End Sub
Reply With Quote
  #2 (permalink)  
Old May 21st, 2005, 11:19 AM
planoie's Avatar
Friend of Wrox
Points: 16,481, Level: 55
Points: 16,481, Level: 55 Points: 16,481, Level: 55 Points: 16,481, Level: 55
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2003
Location: Clifton Park, New York, USA.
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

I don't know where the problem is without knowing what line of code is breaking.

One thing I noticed is that you are using Request.Form. Why are you using that instead of using the controls that are on the page?

Why this:
   valueForsql_student = Replace(Request.Form("Name"), "'", "''")
instead of this:
   valueForsql_student = Replace(Name.Text, "'", "''")

-Peter
Reply With Quote
  #3 (permalink)  
Old May 21st, 2005, 03:35 PM
Registered User
 
Join Date: May 2005
Location: , , .
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi,

I tried your suggestion and received the same error. The stack trace indicates that lines 178 and 297 are suspect.

175 'Check to remove datagrid if no results are returned by query
176 If DS.Tables(0).Rows.Count <= 0 Then
177 dgStudents.Visible = "false"
178 lblMessage.Text = "<b><i>Sorry - no record exist with the last name of: </i></b>" & Name.Text
                End If

293 If rb2.Checked = "True" Then
294 'OnPageIndexChanged = "dgStudents"
295 Panel3.Visible = "true"
296 Panel4.Visible = "false"
297 SBIND()
                End If

[NullReferenceException: Object variable or With block variable not set.]
   Microsoft.VisualBasic.CompilerServices.LateBinding .InternalLateSet(Object o, Type& objType, String name, Object[] args, String[] paramnames, Boolean OptimisticSet, CallType UseCallType) +2049
   Microsoft.VisualBasic.CompilerServices.LateBinding .LateSet(Object o, Type objType, String name, Object[] args, String[] paramnames) +28
   jewishmusic.myFAUSearchNew2.SBIND() in C:\Documents and Settings\tparrish\VSWebCache\develop.fauapps.fau.e du\jewishmusic\myFAUsearchNEW.aspx.vb:178
   jewishmusic.myFAUSearchNew2.Name_TextEnter(Object sender, EventArgs e) in C:\Documents and Settings\tparrish\VSWebCache\develop.fauapps.fau.e du\jewishmusic\myFAUsearchNEW.aspx.vb:297
   System.Web.UI.WebControls.TextBox.OnTextChanged(Ev entArgs e) +108
   System.Web.UI.WebControls.TextBox.System.Web.UI.IP ostBackDataHandler.RaisePostDataChangedEvent() +26
   System.Web.UI.Page.RaiseChangedEvents() +115
   System.Web.UI.Page.ProcessRequestMain() +1099
Reply With Quote
  #4 (permalink)  
Old May 22nd, 2005, 07:40 AM
planoie's Avatar
Friend of Wrox
Points: 16,481, Level: 55
Points: 16,481, Level: 55 Points: 16,481, Level: 55 Points: 16,481, Level: 55
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2003
Location: Clifton Park, New York, USA.
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

I can't debug this for you. You're going to have to figure out what object(s) on the suspect lines of code are Nothing/null.

Is it possible that you made a name change to a control in the webform that didn't get carried thru to the codebehind? This catches me on occasion.

-Peter
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Object variable or With block variable not set haidee_mccaffrey Classic ASP Professional 5 March 8th, 2007 03:34 PM
"object variable or with block variable not set" netfresher ASP.NET 1.0 and 1.1 Basics 1 June 12th, 2006 03:50 PM
object variable or with block variable not set Aoude BOOK: Beginning VB.NET Databases 1 February 24th, 2006 05:21 PM
Object variable or With block variable not set tparrish VB Databases Basics 1 May 25th, 2005 10:25 AM



All times are GMT -4. The time now is 09:34 PM.


Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.