Web Analytics Made Easy -
StatCounter .NET ,,Invisible error when loading dataset from sql - CodingForum

Announcement

Collapse
No announcement yet.

.NET ,,Invisible error when loading dataset from sql

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • .NET ,,Invisible error when loading dataset from sql

    hi

    I have a problem ... I'm using windows_authentication and
    I've tried to test my statement in QA as it returns no dataset ,it gives me empty columns in return,I though it will return all the columns and some records of (lmeyer) as the current user ,who logged in on windows auth,but it return only the columns,is that means my query analyser cannot read the login1 ,column which has the username as (lmeyer)

    select * from tstudents where (login1='@param1')

    if not what could me wrong in my code ,because I get no response /dataset to the sql server



    Public Function login(ByVal login1 as string) as dataset



    Dim myconnection as new sqlconnection("server=G103-TT03;database=CampusLANDB;Trusted_Connection=yes")

    dim mycommand as new sqlcommand ("Select * from tStudents Where login1 = @param1",myconnection)

    mycommand.parameters.add(new SQLClient.SqlParameter("@param1",login1))



    dim DS as new dataset()





    try

    myconnection.open



    dim adpt as new sqldataadapter

    adpt.selectcommand = mycommand

    adpt.fill(DS,"tStudents")





    catch ex as exception

    throw new exception(ex.message)

    return nothing

    finally

    myconnection.close

    end try



    try

    mydatagrid.datasource=DS.Tables("tStudents")

    mydatagrid.databind()

    catch ex as exception

    errorlabel.text=ex.message

    end try



    return DS



    End Function

  • #2
    Try using like instead of equals that is what your problem is I believe.

    dim mycommand as new sqlcommand ("Select * from tStudents Where login1 like @param1",myconnection)

    only use = for integers/numbers and use like for strings

    Eric
    Tech Author [Ajax In Action, JavaScript: Visual Blueprint]

    Comment


    • #3
      Using like is ineffecient unless you actually do need a fuzzy match,
      i.e. user_last_name like 'Sm' .

      For an exact match i.e.
      ...where user_name = 'John Q. Smith' or
      vehicle_make = 'Volkswagen'

      using = is preferred.

      fv

      Comment


      • #4
        I think that might be the case here that is why I suggested it...
        Tech Author [Ajax In Action, JavaScript: Visual Blueprint]

        Comment


        • #5
          thoses parameters are so heavy, why don't you direcly do

          Const _QUERY as string = "select * from tstudents where (login1='{0}') "


          and latter


          Query = String.Format(_QUERY, yourVariable)



          and forget the LIKE in that case
          Last edited by castali; Feb 21, 2004, 03:15 AM.

          Comment


          • #6
            follow ups

            hi again thx for reply


            I'm not sure about this code,is that mean I'm abort my sqlcommand _query line


            dim mycommand as new sqlcommand ("Select * from tStudents Where login1 = @param1"
            and try Const_Query line

            Comment

            Working...
            X