C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Communities   Interview   Jobs   Projects   Offshore Development    
Silverlight Tutorials | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Revenue Sharing |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...

New Feature: Community Sites: Create your own .NET community website and start earning from Google AdSense ! It's Free !




how to solve "Indexoutofrangeexception was unhandled by user code" this error?


Posted Date: 28 Aug 2008      Total Responses: 2

Posted By: gandhi       Member Level: Silver     Points: 1


if i run the following coding i got error in textbox3.text=reader("Enter correct name and password")

error is "Indexoutofrangeexception was unhandled by user code"
Imports System
Imports System.Data.SqlClient
Imports System.Configuration
Imports microsoft.ApplicationBlocks.Data
Partial Class _Default
Inherits System.Web.UI.Page
Protected Sub btOk_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btOk.Click
Dim conn As SqlConnection
conn = New SqlConnection(" server=(local); initial catalog=company; uid=sa; pwd=sa")
Dim cmd As SqlCommand
cmd = New SqlCommand("select * from employee where employeename='textbox1.text' and employeepassword='textbox2.text'", conn)
Dim reader As SqlDataReader
conn.Open()
reader = cmd.ExecuteReader
If reader.Read() Then
textbox1.Text = reader("employeename")
textbox2.Text = reader("employeepassword")
Response.Redirect("Calculation.aspx")
Else
TextBox3.Text = reader("Enter correct name and password")
End If
conn.Close()
End Sub
Protected Sub btExit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btExit.Click
Response.Write("<script language='javascript'> {self.close()} </script>")
End Sub
End Class




Responses

Author: sivapriya    28 Aug 2008Member Level: GoldRating:     Points: 3
i think u get only usrname & password in reader.
there is no value Enter correct name and password in the reader
so try this
TextBox3.Text = "Enter correct name and password"



Author: Sabu C Alex    29 Aug 2008Member Level: GoldRating:     Points: 5
If reader.Read() Then
textbox1.Text = reader("employeename")
textbox2.Text = reader("employeepassword")
Response.Redirect("Calculation.aspx")
Else
TextBox3.Text = reader("Enter correct name and password")
End If

Here in reader you can pass either field index or name of fieldname
you cannot pass value like reader("Enter correct name and password")

i think you have to display message like this

TextBox3.Text = "Enter correct name and password"



Post Reply
You must Sign In to post a response.
Next : dataset
Previous : plz urgent..............
Return to Discussion Forum
Post New Message
Category: ASP.NET

Related Messages



dotNet Slackers   BizTalk Adaptors    Web Design

accuconference

Contact Us    Privacy Policy    Terms Of Use