Please help...

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Ed

    #1

    Please help...

    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="te xt/html" ResponseEncodin g="iso-8859-1" %>
    <%@import namespace="syst em.data"%>
    <%@import namespace="syst em.data.oledb"% >
    <%@import namespace="syst em.data.sqlclie nt"%>
    <script runat=server>
    sub checklastname(S ource as Object,E as EventArgs)
    Dim Conn as oledbconnection
    Dim myadapter as OleDbDataAdapte r
    dim mydataset as new dataset
    conn=new oledbconnection ("Provider=SQLO LEDB;Data Source=datasour cename;Database =databasename;U ser ID=;Password=;" )
    Conn.open()
    myadapter=new OleDbDataAdapte r("Select lastname from testtable where ssn=123121234;" ,conn) ' Error occurs here... becasue 123121234 is not int 'the sysetm
    myadapter.Fill( mydataset,"test ")
    txtlastname.tex t=mydataset.tab les("test").row s(0).Item("last name")
    conn.close()
    end sub

  • Shiva

    #2
    Re: Please help...

    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.Tabl es("test").Rows .Count > 0) Then
    txtlastname.tex t=mydataset.tab les("test").row s(0).Item("last name")
    End If

    "Ed" <Ed@discussions .microsoft.com> wrote in message
    news:8D62ADB0-A22E-4735-9657-2FE70622C278@mi crosoft.com...
    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="te xt/html"
    ResponseEncodin g="iso-8859-1" %>
    <%@import namespace="syst em.data"%>
    <%@import namespace="syst em.data.oledb"% >
    <%@import namespace="syst em.data.sqlclie nt"%>
    <script runat=server>
    sub checklastname(S ource as Object,E as EventArgs)
    Dim Conn as oledbconnection
    Dim myadapter as OleDbDataAdapte r
    dim mydataset as new dataset
    conn=new oledbconnection ("Provider=SQLO LEDB;Data
    Source=datasour cename;Database =databasename;U ser ID=;Password=;" )
    Conn.open()
    myadapter=new OleDbDataAdapte r("Select lastname from testtable where
    ssn=123121234;" ,conn) ' Error occurs here... becasue 123121234 is not int
    'the sysetm
    myadapter.Fill( mydataset,"test ")
    txtlastname.tex t=mydataset.tab les("test").row s(0).Item("last name")
    conn.close()
    end sub


    Comment

    Working...