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