Wrox Programmer Forums
|
ASP.NET 1.0 and 1.1 Basics ASP.NET discussion for users new to coding in ASP.NET 1.0 or 1.1. NOT for the older "classic" ASP 3 or the newer ASP.NET 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.0 and 1.1 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 February 1st, 2006, 12:53 AM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

The error message says it all: "Use 'Is' operator to compare two reference types."

If currentValue Is System.DBNull Then

in your case, you want when it Is NOT, thus:

If Not currentValue Is System.DBNull Then


-Peter
 
Old February 1st, 2006, 01:24 AM
Authorized User
 
Join Date: Jan 2006
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Once again thanks for your answer Peter. Apart from the error, I had problems with the output not being displayed. I got rid of the error as per your suggestion. I'm not sure where I'm going wrong with the code. I'm not even sure if the cod eis right or not.

Could you please give your valuable suggestions.

Thanks in advance

Regards



Praveen
 
Old February 3rd, 2006, 11:30 AM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

What problems are you having now?

-Peter
 
Old February 4th, 2006, 06:02 AM
Authorized User
 
Join Date: Jan 2006
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default

The problem is that when I compile the following code, it doesn't show me any output. The database is connected and the text box (read-only) is also displayed. But the desired output is not obtained.
Code:
<%@ Import namespace="system.data.oledb"%>
<%@ Import namespace="system.data"%>
<%@ Page Language="vb"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
    <HEAD>
        <title>dbtextbox</title>
        <meta name="GENERATOR" content="Microsoft Visual Studio .NET 7.1">
        <meta name="CODE_LANGUAGE" content="Visual Basic .NET 7.1">
        <meta name="vs_defaultClientScript" content="JavaScript">
        <meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
    </HEAD>
    <body MS_POSITIONING="GridLayout">
        <form id="Form1" method="post" runat="server">
            <asp:TextBox id="dumb" style="Z-INDEX: 100; LEFT: 144px; POSITION: absolute; TOP: 96px" runat="server"
                Width="128px" ReadOnly="True"></asp:TextBox>
         </form>     
<script runat="server" language="vb">
sub rate_capture(o as object, e as eventargs)
         dim dtrate as oledbdatareader
         dim con1 as new oledbconnection("Provider=MSDAORA.1;User ID=SCOTT;Password=TIGER;Data Source=HARI")
         con1.open()
         dim cmd1 as new oledbcommand("select rate from test1 where car_code='CAMXL04'",con1)
         dtrate=cmd1.executereader()
         dtrate.close()
         con1.close()

         dumb.Text = String.Empty
        If dtrate.Read() Then
            Dim currentValue As Object = dtrate("rate")
                If not currentValue is System.DBNull.Value Then 
                        dumb.Text = currentValue.ToString().Trim()
                End If
        End If
    end sub
        </script>
    </body>
</HTML>
What I wanted to know is, is this code right in the first place? I'm not pretty much sure about the code. The second thing is that, the contents of this text box is supposed to change according to a drop down list (which I have not included in the above code). Therefore in the query I have given all the conditions that it needs to satisfy to retrieve the data that I want. The following is the table
Table Test1
Name Type
car_code varchar2(8)--> This is the code that I've specified in the query
descript varchar2(50)
rate varchar2(4)--> This is what I want to display in the read only text box according to the above car_code

The car_code is as I've shown in the query "CAMXL04" and the corresponding rate can be, say, 65. The descript could be anything. The only thing that matters to me right now is to display the rate according to the car_code.

Thanks in advance,

Regards,


Praveen
 
Old February 4th, 2006, 08:48 AM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

Try this (I've cleaned up the page a bit to simplify the post:

Code:
<%@ Import namespace="system.data.oledb"%>
<%@ Import namespace="system.data"%>
<%@ Page Language="vb"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
    <HEAD>
        <title>dbtextbox</title>
    </HEAD>
    <body>
        <form id="Form1" method="post" runat="server">
            <asp:dropdownlist id="ddlCars" runat="server"
               OnSelectedIndexChanged="ddlCars_SelectedIndexChanged" />
            <asp:TextBox id="txtRate" runat="server" ReadOnly="True" />
         </form>     
<script runat="server" language="vb">
Dim strConn As String = "Provider=MSDAORA.1;User ID=SCOTT;Password=TIGER;Data Source=HARI"
Sub Page_Load(sender As Object, e As EventArgs)
    If Not IsPostback Then
        dim con as new oledbconnection(strConn)
        dim cmd as new oledbcommand("select car_code,descript from car_code",con)
        con.open()
        ddlCars.datasource=cmd.executereader()
        ddlCars.datatextfield="descript"
        ddlCars.datavaluefield="car_code"
        ddlCars.databind()
        con.close()
    End If
End Sub
Sub ddlCars_SelectedIndexChanged(sender As Object, e As EventArgs)
    Dim strSql As String = "select rate from test1 where car_code='{0}'"
    Dim currentValue As Object
    dim con1 as new oledbconnection(strConn)
    dim cmd1 as new oledbcommand(String.Format(strSql, ddlCars.SelectedValue), con1)
    con1.open()
    currentValue = cmd1.ExecuteScalar()
    con1.close()
    If Not currentValue Is System.DBNull.Value Then 
        txtRate.Text = currentValue.ToString().Trim()
    End If
End Sub
        </script>
    </body>
</HTML>
-Peter





Similar Threads
Thread Thread Starter Forum Replies Last Post
Grab Values From List Box into Text Box phungleon VB How-To 2 June 19th, 2008 10:33 PM
Count in combo box(display results in text box) mboyisis Access 4 April 4th, 2008 07:08 AM
Extract text from text file & put in dropdown box tsukey Beginning PHP 5 July 20th, 2004 09:49 PM
Rich Text Box vs Text Box snowy0 VB.NET 2002/2003 Basics 1 February 17th, 2004 02:11 PM
Search using drop down list box and a text box tcasp Classic ASP Basics 1 July 31st, 2003 02:58 PM





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