Please help...

G

Guest

Hi,
I am very new to .Net I want to connect to SQL Server display data on the web with the following code, but the problem is if I key in a Social Security Number which is not in the SYstem, error occur... what should i DO, thanks, thanks, 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) ' Error occurs here... becasue 123121234 is not int 'the sysetm
myadapter.Fill(mydataset,"test")
txtlastname.text=mydataset.tables("test").rows(0).Item("lastname")
conn.close()
end sub
 
S

Shiva

Hi,
Check whether your SQL query returned any rows before accessing them, by
verifying the number of rows in the dataset table. For example,

If (mydataset.Tables("test").Rows.Count > 0) Then
txtlastname.text=mydataset.tables("test").rows(0).Item("lastname")
End If

Hi,
I am very new to .Net I want to connect to SQL Server display data on the
web with the following code, but the problem is if I key in a Social
Security Number which is not in the SYstem, error occur... what should i
DO, thanks, thanks, 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) ' Error occurs here... becasue 123121234 is not int
'the sysetm
myadapter.Fill(mydataset,"test")
txtlastname.text=mydataset.tables("test").rows(0).Item("lastname")
conn.close()
end sub
 

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

Similar Threads


Top