Please help...

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
 
V

VB Programmer

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=;")
 
G

Guest

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."
 
A

Attila

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top