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 January 25th, 2006, 05:28 AM
Authorized User
 
Join Date: Jan 2006
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default Problem with Drop down list

Hi everyone,
             I'm quite new to this forum as well as ASP.Net too! My problem is a bit confusing to me.I've a drop down list into which I've to populate details from a database. The problem is that I'm having no problems with populating the required information into the list. But I'm not able to insert the same into the database. For verification I'm including the code that I've used for this
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>Entry_Page</title>
        <meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR">
        <meta content="Visual Basic .NET 7.1" name="CODE_LANGUAGE">
        <meta content="JavaScript" name="vs_defaultClientScript">
        <meta content="http://schemas.microsoft.com/intellisense/ie5" name="vs_targetSchema">
    </HEAD>
    <body MS_POSITIONING="GridLayout">
        <form id="Form1" method="post" runat="server">
            <asp:dropdownlist id="ddcars" style="Z-INDEX: 101; LEFT: 136px; POSITION: absolute; TOP: 88px" tabIndex="7"
                runat="server" Height="24px" Width="160px" OnLoad="first_step" OnSelectedIndexChanged="item_change" ></asp:dropdownlist>
            <asp:Label id="Label5" style="Z-INDEX: 112; LEFT: 64px; POSITION: absolute; TOP: 88px" runat="server"
                Height="16px" Width="64px">Car Code</asp:Label>
            <asp:Button id="Button1" style="Z-INDEX: 115; LEFT: 136px; POSITION: absolute; TOP: 120px" runat="server"
                Width="88px" Text="Add"></asp:Button>
            <asp:Label id="Lbl8" style="Z-INDEX: 116; LEFT: 136px; POSITION: absolute; TOP: 24px" runat="server"
                Height="24px" Width="192px" Font-Bold="True">Welcome to the Entry Page</asp:Label></form>
        <script language="vb" runat="server">
            sub first_step(o as object, e as eventargs)
                    dim dtrcars as oledbdatareader
                    dim con as new oledbconnection("Provider=MSDAORA.1;User ID=SCOTT;Password=TIGER;Data Source=HARI")
                    con.open()
                    dim cmd as new oledbcommand("select car_code,descript from car_code",con)
                    dtrcars=cmd.executereader()
                    ddcars.datasource=dtrcars
                    ddcars.datatextfield="descript"
                    ddcars.datavaluefield="car_code"
                    ddcars.databind()
                    dtrcars.close()
                    con.close()
            end sub
            dim sitem as string
            sub item_change ( o as object, e as eventargs)
            sitem=ddcars.selecteditem.text
            end sub
            sub button_click(o as object, e as eventargs)
                dim con1 as new oledbconnection("Provider=MSDAORA.1;User ID=SCOTT;Password=TIGER;Data Source=HARI")
                dim name,addr,phno,mbno,fxno,mail,ccode as string
                dim hdat as date
                ccode=request.form("ddcars")
                dim str1 as string
                str1="insert into rent_car1(car_code) values('" & ccode & "')"
                con1.open()
                dim cmd1 as new oledbcommand(str1,con1)
                dim x as integer
                x = cmd1.executenonquery()
                response.write("Entry Added")
                end sub
        </script>
    </body>
</HTML>
I've used the Oracle as my database, since access caused me some rights issues which I could not sort out. The details of the tables from where I've to populate the data into the list and to which I've to insert the same is included below:

Test1 is the table from where I've to populate the drop down list.
 Name Type
 ------------ ------------------------------------
 CAR_CODE VARCHAR2(8)
 DESCRIPT VARCHAR2(50)
Example
let the car_code be "CAMXL05" and it's respective descript be "Toyota Camry XLi,2005"

For the time being I'm just trying to update the contents of the drop down list item into the database.

Test2 is the table to which I've to insert the data
Name Type
----------- -----------------------
CAR_CODE VARCHAR2(8)

The car_code "CAMXL05" is what I want to insert into the database.

Forgive me for my lack of technical vocabulary. I would be greatful if some one can really help me out.

Praveen
__________________
Praveen
 
Old January 25th, 2006, 05:32 AM
Authorized User
 
Join Date: Jan 2006
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default

One more thing, the queries in the code that I've posted have got the wrong table names. The table name "car_code" can be replaced by "test1" and "rent_car1" can be replaced by "test2". Pardon me for the error.

Praveen
 
Old January 25th, 2006, 09:40 AM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

First off, you should hardly ever need to reference the Request property of the page like we used to in classic ASP:
   ccode=request.form("ddcars")

Get the value directly from the control:
   ddcars.SelectedIndex
or
   ddcars.SelectedValue


It looks like the problem is that you aren't calling your button click handler "button_click(...)". You need to specify this in the button markup:
Code:
<asp:Button id="Button1" style="Z-INDEX: 115; LEFT: 136px; POSITION: absolute; TOP: 120px"
   runat="server" Width="88px" Text="Add" onclick="button_click"></asp:Button>
                                          ^                    ^
                                          ^--------------------^
-Peter
 
Old January 26th, 2006, 05:55 AM
Authorized User
 
Join Date: Jan 2006
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Peter thanks a lot for your help. I admit that it was a silly mistake from my side. Once again I thank you for sparing your precious time on my problem.



Praveen





Similar Threads
Thread Thread Starter Forum Replies Last Post
Drop Down List problem tgnishant ASP.NET 2.0 Basics 1 March 12th, 2007 08:10 AM
problem in selecting the item from drop down list swati_joshi ASP.NET 1.0 and 1.1 Basics 1 March 27th, 2006 01:24 AM
drop down list values based on another drop down noor ASP.NET 1.0 and 1.1 Basics 3 July 5th, 2005 09:57 AM
Drop Down List Beginner123 VB How-To 2 March 7th, 2005 01:56 PM





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