Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Visual Basic > VB 6 Visual Basic 6 > VB Databases Basics
|
VB Databases Basics Beginning-level VB coding questions specific to using VB with databases. Issues not specific to database use will be redirected to other forums.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the VB Databases Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old May 20th, 2005, 09:35 PM
Registered User
 
Join Date: May 2005
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
 
Old May 25th, 2005, 10:25 AM
Friend of Wrox
 
Join Date: Nov 2004
Posts: 1,621
Thanks: 1
Thanked 3 Times in 3 Posts
Default

Do you think you could help... a little?

First of all, at which point in your code does the error occur?

Second, you have within what you posted that which all of us have in our code: lines of code remmed out.
But why do you make us try to separate the abandoned from the active? Couldn't you go through your posting, and at least remove the commented out lines of abandoned code?

If you start your code listing with a pair of square brackets (“[]”) with the word “code” between them, and end your block of code with the same thing, but “/code” instead of “code” between the brackets, your listing will begin and end with a line feed, and will be fixed-pitch, making it a lot easier to follow.

If you will at least indicate the line that throws the error, I'd like to try to help.

Brian





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 VS.NET 2002/2003 3 May 22nd, 2005 07:40 AM





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