|
the error i am getting on browser page is :-
"Server Error in '/Website_dtc' Application.
--------------------------------------------------------------------------------
Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.
"
the RadiobuttonList is databound as follows-
"RadioButtonList1.DataSource = ds.Tables["temp1"];
RadioButtonList1.DataTextField = "buses";
RadioButtonList1.DataValueField = "buses";
RadioButtonList1.DataBind();
"
the RadiobuttonList Item is selected as:-
" protected void Button1_Click(object sender, EventArgs e)
{
lbltemp.Text = RadioButtonList1.SelectedItem.Text;
}
"
|
|
|
|
|
At a guess, either
a) you haven't selected anything in the list
or
b) you rebind the list each time the page loads, thus overwriting the selection... Might want to have a look at the IsPostBack page variable.
|
|
|
|
|
dear paddy ..
this is my Source Code for the Page--
"<%@ Page Language="C#" AutoEventWireup="true" CodeFile="searchstops_1.aspx.cs" Inherits="searchstops_1" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<!--
Design by Free CSS Templates
http://www.freecsstemplates.org
Released for free under a Creative Commons Attribution 2.5 License
Name : Monoblock
Description: A two-column, fixed-width design with dark color scheme.
Version : 1.0
Released : 20080418
-->
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>DTC_Services</title>
<meta name="keywords" content="" />
<meta name="description" content="" />
<link href="style.css" rel="stylesheet" type="text/css" media="screen" />
<script language="javascript" type="text/javascript">
<!--
function content_onclick() {
}
// -->
</script>
</head>
<body>
<form id="form1" runat="server">
<div id="header" style="width: 1202px">
<div id="logo">
</div>
<br />
<br />
<br />
<br />
<br />
<br />
<asp:Label ID="Label1" runat="server" Font-Bold="True" Font-Size="X-Large" ForeColor="Black"
Style="z-index: 100; left: 39px; position: absolute; top: 23px" Text="DELHI TRANSPORT CORPORATION"></asp:Label>
<br />
<asp:Image ID="Image2" runat="server" ImageUrl="~/PICS/logo1.gif" Style="z-index: 101;
left: 1014px; position: absolute; top: 31px" />
<br />
<br />
<!-- end #search -->
<br />
</div>
<!-- end #header -->
<div id="menu" style="width: 1202px">
<br />
<strong><span style="color: #ffffcc">
<span style="font-size: 14pt; font-family: Verdana"><a href="home.aspx">Home </a>
<a href="home.aspx">Services Offered </a>
<a href="home.aspx">Apply for DTC pass</a> <a href="home.aspx">Contact
Us</a> <a href="home.aspx">Help </a></span><span style="font-size: 14pt">
</span></span></strong></div>
<!-- end #menu -->
<div id="page" style="width: 1121px; height: 635px">
<!-- end #content -->
<div id="sidebar" style="height: 690px">
<ul>
<li>
<h2>
buses at a glance</h2>
<p>
</p>
<p>
</p>
<p>
<asp:Image ID="Image1" runat="server" ImageUrl="~/PICS/2008053054180501.jpg" Style="z-index: 100;
left: 914px; position: absolute; top: 370px" Height="126px" />
</p>
</li>
<li id="calendar">
<h2>
Services offered</h2>
<div id="calendar_wrap">
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
</div>
</li>
</ul>
</div>
<div style="clear: both;">
<div class="entry">
<asp:HyperLink ID="HyperLink4" runat="server" NavigateUrl="~/home.aspx" Style="z-index: 100;
left: 924px; position: absolute; top: 733px" Width="208px">Buses through a stoppage</asp:HyperLink>
<asp:Panel ID="Panel1" runat="server" Height="691px" Style="z-index: 105; left: 46px;
position: absolute; top: 255px" Width="823px">
<br />
<br />
<span style="font-size: 16pt">Services offered >><br />
<span style="font-size: 14pt">
Search Buses by Stops<br />
<asp:Label ID="lblsrc" runat="server" Font-Bold="False" ForeColor="Green" Style="z-index: 100;
left: 580px; position: absolute; top: 300px"></asp:Label>
<asp:Label ID="lbldes" runat="server" Font-Bold="False" ForeColor="Green" Style="z-index: 101;
left: 153px; position: absolute; top: 305px"></asp:Label>
<br />
<asp:Label ID="Label2" runat="server" Font-Italic="True" Font-Size="Smaller" ForeColor="Red"
Style="z-index: 102; left: 348px; position: absolute; top: 128px" Text="You Selected"></asp:Label>
<br />
<span style="font-size: 12pt; color: #ff0000"><em>
<asp:Label ID="Label4" runat="server" Font-Bold="True" Font-Underline="True" Style="z-index: 103;
left: 155px; position: absolute; top: 230px" Text="SOURCE"></asp:Label>
<%--<asp:RadioButtonList ID="RadioButtonList1" runat="server" Style="z-index: 104; left: 344px;
position: absolute; top: 476px" OnSelectedIndexChanged="RadioButtonList1_SelectedIndexChanged">
</asp:RadioButtonList>--%>
<br />
<br />
<asp:Label ID="Label3" runat="server" Font-Bold="True" Font-Underline="True" Style="z-index: 104;
left: 580px; position: absolute; top: 226px" Text="DESTINATION"></asp:Label>
<br />
<br />
</em></span>
<span style="font-size: 12pt; color: #cc0000"><strong>
<asp:Label ID="Label5" runat="server" Font-Size="Smaller" Style="z-index: 105; left: 264px;
position: absolute; top: 410px" Text="Following Bus Routes are available"></asp:Label>
<asp:RadioButtonList ID="RadioButtonList1" runat="server" Style="z-index: 106; left: 333px;
position: absolute; top: 467px" AutoPostBack="True" OnSelectedIndexChanged="RadioButtonList1_SelectedIndexChanged">
</asp:RadioButtonList>
<asp:Label ID="lbltemp" runat="server" Style="z-index: 108; left: 628px; position: absolute;
top: 462px"></asp:Label>
</strong></span></span></span></asp:Panel>
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<asp:HyperLink ID="HyperLink5" runat="server" NavigateUrl="~/home.aspx" Style="z-index: 102;
left: 929px; position: absolute; top: 864px" Width="204px">Apply for DTC pass</asp:HyperLink>
<asp:HyperLink ID="HyperLink2" runat="server" NavigateUrl="~/home.aspx" Style="z-index: 103;
left: 926px; position: absolute; top: 800px" Width="210px">Search by Bus No.</asp:HyperLink>
<asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl="~/home.aspx" Style="z-index: 104;
left: 928px; position: absolute; top: 662px" Width="211px">Search Buses by Stops</asp:HyperLink>
</div>
</div>
</div>
<div style="font-size: 0.8em; text-align: center; margin-top: 1.0em; margin-bottom: 1.0em;">
</div>
</form></body>
</html>
"
Here is The CODE SEGMENT
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
public partial class searchstops_1 : System.Web.UI.Page
{
SqlConnection con = new SqlConnection();
SqlDataAdapter adp = new SqlDataAdapter();
DataSet ds = new DataSet();
protected void Page_Load(object sender, EventArgs e)
{
con.ConnectionString = ConfigurationManager.ConnectionStrings["dtcConnect"].ConnectionString;
con.Open();
lblsrc.Text = Session["source"].ToString();
lbldes.Text = Session["dest"].ToString();
String str;
str = "select *from busno where exists (select 1 from busroutes bs1 where bs1.busno=busno.buses and bs1.stops='" + Session["source"].ToString() + "') and exists (select 1 from busroutes bs2 where bs2.busno=busno.buses and bs2.stops='" + Session["dest"].ToString() + "')";
adp.SelectCommand = new SqlCommand(str, con);
adp.SelectCommand.ExecuteNonQuery();
adp.Fill(ds, "temp1");
RadioButtonList1.DataSource = ds.Tables["temp1"];
RadioButtonList1.DataTextField = "buses";
RadioButtonList1.DataValueField = "buses";
RadioButtonList1.DataBind();
}
protected void Button2_Click(object sender, EventArgs e)
{
Response.Redirect("searchstops.aspx");
}
protected void RadioButtonList1_SelectedIndexChanged(object sender, EventArgs e)
{
if (RadioButtonList1.SelectedIndex != -1)
lbltemp.Text = RadioButtonList1.SelectedItem.Text;
}
}
"
thanx for the help
|
|
|
|
|
Thanx Paddy..my problem was solved...
|
|
|
|
|
That error will occur if you click the button when you have not selected any of the radio buttons on the RadioButtonList1. So you need to check whether the selection has first happened. Probably using:
if (RadioButtonList1.SelectedIndex != -1)
lbltemp.Text = RadioButtonList1.SelectedItem.Text;
|
|
|
|
|
I am inserting record in table using stored procedure.
CREATE PROCEDURE add_member(
@UserName Varchar( 50 ),
@Password Varchar( 50 ),
@dob datetime,
@education Varchar(50),
@designation Varchar(50),
@name Varchar(50)
) AS
If Exists( SELECT username FROM member WHERE username = @username )
RETURN -1
ELSE
BEGIN
DECLARE @ID int -- new ID value holder
INSERT member (
username, password, dob, education, designation, name
) VALUES (
@username, @password, @dob, @education, @designation, @name
)
-- get the new identity column value
SET @id = @@IDENTITY
END
GO
-------------------------------
I am using classic asp to add records in this way -
sql = "add_member " & "'" & request.form("username") & "'" & "," & "'" & request.form("password") & "'" & "," & "'2/2/2'" & "," & request.form("education") & "," & request.form("designation") & "," & "'" & request.form("name") & "'"
set rsAdd = Server.CreateObject("ADODB.Recordset")
rsAdd.Open sql, con
Its adding new record successfully But I am not able to read id of newly added record.
Plzzzzzzz help
|
|
|
|
|
That's because you aren't returning it. You set @ID, but you need to either set an output parameter or select @ID to return it to your code.
Bob
Ashfield Consultants Ltd
|
|
|
|
|
How to return and read in asp please explain in detail
Thanks in advance
|
|
|
|
|
You can either use an OUTPUT parameter in your query (search SQL Help for OUTPUT PARAMETER) or simply do a select and return the value in a recordset just like any other select statement does. An output parameter is more efficient.
To be honest, its so long since I used ADODB that I can't remember the syntax for retriving output parameters, but I do remeber you have to close the recordset first, strange as it seems.
Hopefully this will give you some pointers to enable you to resolve your problem after a little work on Google.
Bob
Ashfield Consultants Ltd
|
|
|
|
|
Add this as you last line.
Select @ID as ID
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Then How to read this value in asp
|
|
|
|
|
The resilt can be used as either executescalar directly to a varaible or as a dataset/table using .fill.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Hi dear,
I have one problem so u please solve that.
i am using sql server 2000.
In my working time sudennly sql server service manager is stopped,then i tried to start the sql server service manager,but it can't start...how to solve this problem...
please help me.
thanks in advance...
modified on Thursday, October 23, 2008 5:45 AM
|
|
|
|
|
Have you looked in task manager to see if its really gone? You may have to kill the process. Failing that, how about a reboot?
Bob
Ashfield Consultants Ltd
|
|
|
|
|
Hi...
can anyone please tell me "What are the various debug visualizers in visual studio ?"
thanks
deep.
|
|
|
|
|
Text Visualizer, XML Visualizer, HTML Visualizer
|
|
|
|
|
I have a problem when rollback a transaction. I create a stored procedure as follow:
CREATE PROCEDURE [dbo].[sp_test] AS
begin transaction
declare @Res int
select * into abc from sysusers
delete from abc123 --an error is raised cause there is no abc123 table
Set @Res = @@Error
if @Res <> 0
Rollback transaction
else
Commit transaction
When I execute this stored procedure from Querry Analyzer:
Exec sp_test
It shows an error message:
Invalid object name 'abc123'.
Transaction count after EXECUTE indicates that a COMMIT or ROLLBACK TRANSACTION statement is missing. Previous count = 0, current count = 1.
The problem here is that: when a statement makes error (select,delete, insert), SQL Server 2000 stop executing other statement. So, the rollback transaction statement has no meaning.
Please help me to solve this problem. All I want is to rollback a stored procedure when never there is an error.
Thanks.
adfafafa
|
|
|
|
|
If there is no table abc123 then the proc will not compile so you are not getting a data error you are getting a syntax error in your code.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
I create this proc in SQL Server 2000 and I think this proc will be compiled because there is no syntax error (I have checked syntax error after creating). Instead, it will cause run-time error because there is no abc123 table in the data base.
The problem is SQL Server 2000 stop executing other statement when it gets an error in select,delete,insert or update statement.
I've tried to use:
SET XACT_ABORT ON
to rollback other statements in the transaction but it still making error cause: ROLLBACK or COMMIT are not executed after BEGIN TRAN.
Please run my proc then help me to solve this problem.
Thank you very much.
CREATE PROCEDURE [dbo].[sp_test] AS
SET XACT_ABORT ON
DECLARE @Res int
begin transaction
select * into abc from sysusers
delete from abc123
Set @Res = @@ERROR
if @Res <> 0
ROLLBACK TRANSACTION
else
COMMIT TRANSACTION
GO
adfafafa
|
|
|
|
|
I don't think you are going to get transaction processing to do what you want, you are using the wrong tool, you should check for the existence of the table before you attempt to process against that table.
[rant]
IMHO your design stinks, if there is a possibility that a table does not exist in the database I am betting your design is wrong.
Another thing - relying on transactions stink, this is a classic "programming by error", if there is no error then it worked and we can continue when you should validate the data before attempting to process it. Error traps/transaction are to trap faults they are not a tool to make your programming life easier, the only time you should get into an error trap is during development or there is an environment issue.
[/rant]
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
I am using 'ADOX.Catalog' namespace and the following code to create a new MS Access database.
Private Function CreateAccessDatabase() As Boolean
'-------------------------------------------------------
'This method is called to create a new Access database
'Required: NewDBConnectionString
'-------------------------------------------------------
Dim ADOXCatalog As New ADOX.Catalog
Try
If Me.NewDBConnectionString.Trim.ToString.Length = 0 Then Throw New Exception("Connection string is not specified")
'Call create method to create a new database
ADOXCatalog.Create(Me.NewDBConnectionString.Trim.T oString)
Return True
Catch ex As Exception
Throw ex
Return False
Finally
If Not ADOXCatalog Is Nothing Then
ADOXCatalog = Nothing
End If
End Try
End Function
The moment it created database, it is also leaving a .ldb file in the same directory. I don't want that .ldb file. If I tried to delete the file forcedly, it is passing an exception "The file is being used....". All the connection strings are properly closed.
Can anyone help me to remove this .ldb file.
|
|
|
|
|
|
SELECT COLUMN_NAME FROM USER_TAB_COLUMNS WHERE TABLE_NAME = 'ONE_ROW_TABLE';
Will get me the column names, ok, when this table is meant to be a one-row table, how can I get the column names of that table that has a value of say '0'
Example:
ONE_ROW_TABLE
COL1 COL2 COL3 COL4 COL5
---- ---- ---- ---- ----
1 0 1 0 0
I want to see an output like:
COL1
COL3
Thank you guys!
All generalizations are wrong, including this one!
(\ /)
(O.o)
(> <)
<div class="ForumMod">modified on Wednesday, October 22, 2008 4:45 AM</div>
|
|
|
|
|
You can create a query using UNION to make it row based or a dynamic query using the case statement for a column based answer.
Need software developed? Offering C# development all over the United States, ERL GLOBAL, Inc is the only call you will have to make.
Happiness in intelligent people is the rarest thing I know. -- Ernest Hemingway
Most of this sig is for Google, not ego.
|
|
|
|
|
How??
All generalizations are wrong, including this one!
(\ /)
(O.o)
(><)
|
|
|
|