Please help...

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,
I would like to have my web connect to a SQL Server and display data on a web form. My question is if a Social Security Number is not is the database, error occurs... what should i do... thanks

<%@ Page Language="VB" debug="true" ContentType="text/html" ResponseEncoding="iso-8859-1" %>
<%@import namespace="system.data"%>
<%@import namespace="system.data.oledb"%>
<%@import namespace="system.data.sqlclient"%>
<script runat=server>
sub checklastname(Source as Object,E as EventArgs)
Dim Conn as oledbconnection
Dim myadapter as OleDbDataAdapter
dim mydataset as new dataset
conn=new oledbconnection ("Provider=SQLOLEDB;Data Source=datasourcename;Database=databasename;User ID=;Password=;")
Conn.open()
myadapter=new OleDbDataAdapter("Select lastname from testtable where ssn=123121234;",conn)
myadapter.Fill(mydataset,"test") 'Error occurs since the number 123121234 is 'not in the system
txtlastname.text=mydataset.tables("test").rows(0).Item("lastname")
conn.close()
end sub
 
What error are you getting?

Ed said:
Hi,
I would like to have my web connect to a SQL Server and display data on
a web form. My question is if a Social Security Number is not is the
database, error occurs... what should i do... thanks
<%@ Page Language="VB" debug="true" ContentType="text/html"
ResponseEncoding="iso-8859-1" %>
<%@import namespace="system.data"%>
<%@import namespace="system.data.oledb"%>
<%@import namespace="system.data.sqlclient"%>
<script runat=server>
sub checklastname(Source as Object,E as EventArgs)
Dim Conn as oledbconnection
Dim myadapter as OleDbDataAdapter
dim mydataset as new dataset
conn=new oledbconnection ("Provider=SQLOLEDB;Data
Source=datasourcename;Database=databasename;User ID=;Password=;")
 
Thanks for your response, the error is as follow:
should be happen at this statement
txtlastname.text=mydataset.tables("test").rows(0).Item("lastname")

"There is no row at position 0.
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.IndexOutOfRangeException: There is no row at position 0."
 
I might recommend checking whether the row exists before trying to access it
with something like this:

if mydataset.tables("test").rows.count > 0 then
//assign to variable
else
//don't try to assign the value to a variable
end if

hth

attila

Ed said:
Thanks for your response, the error is as follow:
should be happen at this statement
txtlastname.text=mydataset.tables("test").rows(0).Item("lastname")

"There is no row at position 0.
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.
 
Back
Top