Using SQLDataSource without a control?

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

    #1

    Using SQLDataSource without a control?

    This is probably easy but I cannot find it...

    All I want to do is read the data out of a SQLDataSource programmaticall y to
    test if there are any records.
    I don't want to bind it to a control

    I expected to be able to use it like the below

    Dim ds as dataset
    SqlDataSource1. fill ( ds) ' does not work

    So, can this be done or do I need to create a hidden gridview to receive the
    data?

    Thanks

    Bill


  • Spam Catcher

    #2
    Re: Using SQLDataSource without a control?

    "Bill" <aa@ss.comwro te in
    news:4dmHg.8947 $bZ6.7643@torna do.tampabay.rr. com:
    All I want to do is read the data out of a SQLDataSource
    programmaticall y to test if there are any records.
    Use a SQLCommand object... and execute a scalar command like "SELECT COUNT
    (1) FROM TABLE"

    http://msdn2.microsoft.com/en-
    us/library/system.data.sql client.sqlcomma nd.executescala r.aspx

    Comment

    • RJ

      #3
      RE: Using SQLDataSource without a control?

      I agree with using "Select Count(*)" with a cmd.executeScal er.

      But, In your example with DataSource1.Fil l..... I think you need
      SqlDataAdapter. Fill(ds)


      "Bill" wrote:
      This is probably easy but I cannot find it...
      >
      All I want to do is read the data out of a SQLDataSource programmaticall y to
      test if there are any records.
      I don't want to bind it to a control
      >
      I expected to be able to use it like the below
      >
      Dim ds as dataset
      SqlDataSource1. fill ( ds) ' does not work
      >
      So, can this be done or do I need to create a hidden gridview to receive the
      data?
      >
      Thanks
      >
      Bill
      >
      >
      >

      Comment

      • Bill

        #4
        Re: Using SQLDataSource without a control?

        Thanks for the suggestions but I was looking for a way to use the
        SQLDataSource control to reduce coding, not using the usual SQL objects.

        I did find an answer so here it is:

        Dim DV As New DataView

        Dim xx As New DataSourceSelec tArguments

        ' get records into dataview

        DV = SqlDataSource1. Select(xx.Empty )

        ' if no active messages then hide link

        If DV.Count < 1 Then HyperLink1.Visi ble = False



        Note that the above is ALL of the code needed since I am using the GUI
        connection component & wizard to create the connection and string as the
        control SQLDataSource1

        Bill



        "RJ" <RJ@discussions .microsoft.comw rote in message
        news:DBAD8366-DF9B-43C5-80BD-05492CBD5BC3@mi crosoft.com...
        >I agree with using "Select Count(*)" with a cmd.executeScal er.
        >
        But, In your example with DataSource1.Fil l..... I think you need
        SqlDataAdapter. Fill(ds)
        >
        >
        "Bill" wrote:
        >
        >This is probably easy but I cannot find it...
        >>
        >All I want to do is read the data out of a SQLDataSource programmaticall y
        >to
        >test if there are any records.
        >I don't want to bind it to a control
        >>
        >I expected to be able to use it like the below
        >>
        >Dim ds as dataset
        >SqlDataSource1 . fill ( ds) ' does not work
        >>
        >So, can this be done or do I need to create a hidden gridview to receive
        >the
        >data?
        >>
        >Thanks
        >>
        >Bill
        >>
        >>
        >>

        Comment

        Working...