 |
| 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
|
|
|
|

January 27th, 2006, 04:32 AM
|
|
Authorized User
|
|
Join Date: Jan 2006
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Text Box
My problem is that I want to retrieve data from database based on some parameters, say some query. Say, I have a table test1
Name Type
car_code varchar2(8)
descript varchar2(50)
rate varchar2(4)
I've a text box called rate which is read-only. I want to display the rate of the car based on the car_code selected. But I dont get how to do this. I'm just a newbie in asp.net and I'm using just the plain asp.net tags. I would be greatful if some one could help me out.
Praveen
__________________
Praveen
|
|

January 27th, 2006, 07:48 AM
|
|
Authorized User
|
|
Join Date: Jan 2006
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
I missed out on one more thing. Suppose the car_code is "CAMXL05" and it's corresponding rate is "65" how can i display the rate for the car_code selected?
Praveen
|
|

January 27th, 2006, 11:04 AM
|
 |
Friend of Wrox
|
|
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
|
|
What do you have so far?
You need to get the date from the database then assign the value to the textbox .Text property.
- Peter
|
|

January 27th, 2006, 01:05 PM
|
|
Authorized User
|
|
Join Date: Jan 2006
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
I'm sorry that I did not state anything about the progress that I've made so far.
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 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" OnLoad="first_step"></asp:TextBox>
<asp:dropdownlist id="ddcars" style="Z-INDEX: 101; LEFT: 144px; POSITION: absolute; TOP: 56px" tabIndex="8"
runat="server" OnLoad="first_step" Width="232px" Height="24px">
<asp:ListItem></asp:ListItem>
</asp:dropdownlist>
</form>
<script runat="server" language="vb">
sub first_step(o as object, e as eventargs)
if not ispostback then
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 if
end sub
</script>
</body>
</HTML>
Well about the progress, I've made not much progress. The only thing is that I've populated the drop down list. But I've to get the rate loaded from the database for the car_code that is being selected from the drop down list. Only then I can proceed further.
Once again thanks in advance.
Praveen
|
|

January 27th, 2006, 09:51 PM
|
 |
Friend of Wrox
|
|
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
|
|
The method you use to do the initial load should be the page_load method. This will be wired automatically for you when you use that name. Then you can use the selectedindexchanged event of the dropdown list to fire off the next step.
- Peter
|
|

January 28th, 2006, 04:04 AM
|
|
Authorized User
|
|
Join Date: Jan 2006
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Thanks for your answer Peter. But as I've told earlier, since I'm a newbie in this area could you please elaborate on your point a bit more? I mean I did get your point, but that's half understood to me. Well I did try it out but it just doesn't seem to be working or is it my lack of understanding the point that you put forward. Either case I did not understand the whole thing.
Once again thanks in advance.
Regards,
Praveen
|
|

January 28th, 2006, 05:01 AM
|
 |
Friend of Wrox
|
|
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
|
|
You obviously have a grasp on how to get data from the database as is evident by the binding to the dropdown list. How about writing the part that gets data from the DB for the exact thing you need. Don't think about tying in the dropdownlist yet, just write the database access peice of it. Then we can direct you as to how to tie it together. ALso, there are many many tutorials online that can get you started with this kind of task.
- Peter
|
|

January 28th, 2006, 06:40 AM
|
|
Authorized User
|
|
Join Date: Jan 2006
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
As you have suggested I'm including the part that I want exactly with the database access. As of now I've included the code in the query. Later on I'll include the one from the form. The car_code is "CAMXL04" and it's rate is say some 65 or something. But for now this is how it looks.
Code:
<%@ Page Language="vb"%>
<%@ Import namespace="system.data"%>
<%@ Import namespace="system.data.oledb"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<title>dbtextbox</title>
</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>
<asp:dropdownlist id="ddcars" style="Z-INDEX: 101; LEFT: 144px; POSITION: absolute; TOP: 56px" tabIndex="8"
runat="server" Width="232px" Height="24px" OnSelectedIndexChanged="rate_capture">
<asp:ListItem></asp:ListItem>
</asp:dropdownlist>
</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 car_code where car_code='CAMXL04'",con1)
dtrate=cmd1.executereader()
dtrate.close()
con1.close()
end sub
</script>
</body>
</HTML>
I'm not pretty much sure about what to do after the query. This is because I've no idea of how to do it. And for the tutorials, I've looked for it everywhere. I could not site one that was suiting my requirements, though there were some but it was all coded in different languages. As I'm only used to the server script I could not find one that was done in server scripts. If you could suggest any tutorials that is suitable for beginners like me I would be greatful.
Thanks in advance.
Regards
Praveen
|
|

January 30th, 2006, 02:41 AM
|
|
Authorized User
|
|
Join Date: Jan 2006
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Can anyone please help me out with the above topic
Thanks in advance
Regards
Praveen
|
|

January 31st, 2006, 02:35 PM
|
|
Authorized User
|
|
Join Date: Jan 2006
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Hi everyone,
I found a way out to my problem through hours and hours of browsing in the net. But the method that I found is also proving to be an utter failure. Can anyone help me in this? The following is the code that I made up by going through a PDF file.
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>
<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 car_code where car_code='CAMXL04'",con1)
dtrate=cmd1.executereader()
dtrate.close()
con1.close()
'****The following code is what I got after referring to the document.
dumb.Text = String.Empty
If dtrate.Read() Then
Dim currentValue As Object = dtrate("rate")
If currentValue <> System.DBNull.Value Then
dumb.Text = currentValue.ToString().Trim()
End If
End If
end sub
</script>
</body>
</HTML>
In spite of adding this code, my requirements are still not met. I dont get the exact reason of it not working. Could any one suggest me a way out. When I compile the above code I get the following error and I did not understand what exactly does it imply.
BC31080: Operator '<>' is not defined for types 'System.Object' and 'System.DBNull'. Use 'Is' operator to compare two reference types.
I would be greatful if some one could help me out of this problem.
Thanks in advance
Regards
Praveen
Praveen
|
|
 |