Binding a Database to Datagrid / Repeater

Discussion in 'ASP .Net' started by Kristoffer Arfvidson, Jan 29, 2004.

  1. How, do I bind a database to either a Datagrid or a repeater (via
    PagedDataSource)??

    Im, trying everything, but I simply cant get it...
    I use RS.GetRows to get all the info at once from the database...

    I always gets the error msg that the datasource was not an one dimensional
    array, witch of course it isn´t, but how else am I going to bind the data?

    Yours: Kristoffer
    --------------------------------
    Dim objConn As New ADODB.Connection

    Dim cm As New ADODB.Command

    Dim tmpRs As New ADODB.Recordset

    objConn.CursorLocation = ADODB.CursorLocationEnum.adUseClient

    ' Create a command object. This object serves to run our queries

    objConn.Open(sConnectDP)

    cm.CommandText = sSqlStr

    ' Set the query type. 1 means it is a SQL statement

    cm.CommandType = 1

    ' Retrieve the results in a recordset object

    cm.ActiveConnection = objConn

    tmpRs = cm.Execute

    DataGrid1.DataSource = tmpRs.GetRows

    DataGrid1.DataBind()

    tmpRs.Close()

    tmpRs = Nothing

    cm = Nothing

    objConn.Close()

    objConn = Nothing
    Kristoffer Arfvidson, Jan 29, 2004
    #1
    1. Advertising

  2. Kristoffer Arfvidson

    Stephan Bour Guest

    Could you show us the code for DataGrid1?


    in article , Kristoffer Arfvidson at
    wrote on 1/29/04 4:32 PM:

    > How, do I bind a database to either a Datagrid or a repeater (via
    > PagedDataSource)??
    >
    > Im, trying everything, but I simply cant get it...
    > I use RS.GetRows to get all the info at once from the database...
    >
    > I always gets the error msg that the datasource was not an one dimensional
    > array, witch of course it isn´t, but how else am I going to bind the data?
    >
    > Yours: Kristoffer
    > --------------------------------
    > Dim objConn As New ADODB.Connection
    >
    > Dim cm As New ADODB.Command
    >
    > Dim tmpRs As New ADODB.Recordset
    >
    > objConn.CursorLocation = ADODB.CursorLocationEnum.adUseClient
    >
    > ' Create a command object. This object serves to run our queries
    >
    > objConn.Open(sConnectDP)
    >
    > cm.CommandText = sSqlStr
    >
    > ' Set the query type. 1 means it is a SQL statement
    >
    > cm.CommandType = 1
    >
    > ' Retrieve the results in a recordset object
    >
    > cm.ActiveConnection = objConn
    >
    > tmpRs = cm.Execute
    >
    > DataGrid1.DataSource = tmpRs.GetRows
    >
    > DataGrid1.DataBind()
    >
    > tmpRs.Close()
    >
    > tmpRs = Nothing
    >
    > cm = Nothing
    >
    > objConn.Close()
    >
    > objConn = Nothing
    >
    >
    Stephan Bour, Jan 29, 2004
    #2
    1. Advertising

  3. Sure, I havnt really done anything to the datagrid1 control...
    I simply added it to the document so far...
    Of course I will need Templates on it, to make it usefull on my page, but I
    wanted to first get the databinds done, so I then can figure out how to make
    the design work...

    Yours: Kristoffer
    ----------
    <asp:DataGrid id="DataGrid1" runat="server"></asp:DataGrid>


    "Stephan Bour" <> skrev i meddelandet
    news:BC3EEE7F.E7C1%...
    > Could you show us the code for DataGrid1?
    >
    >
    > in article , Kristoffer Arfvidson at
    > wrote on 1/29/04 4:32 PM:
    >
    > > How, do I bind a database to either a Datagrid or a repeater (via
    > > PagedDataSource)??
    > >
    > > Im, trying everything, but I simply cant get it...
    > > I use RS.GetRows to get all the info at once from the database...
    > >
    > > I always gets the error msg that the datasource was not an one

    dimensional
    > > array, witch of course it isn´t, but how else am I going to bind the

    data?
    > >
    > > Yours: Kristoffer
    > > --------------------------------
    > > Dim objConn As New ADODB.Connection
    > >
    > > Dim cm As New ADODB.Command
    > >
    > > Dim tmpRs As New ADODB.Recordset
    > >
    > > objConn.CursorLocation = ADODB.CursorLocationEnum.adUseClient
    > >
    > > ' Create a command object. This object serves to run our queries
    > >
    > > objConn.Open(sConnectDP)
    > >
    > > cm.CommandText = sSqlStr
    > >
    > > ' Set the query type. 1 means it is a SQL statement
    > >
    > > cm.CommandType = 1
    > >
    > > ' Retrieve the results in a recordset object
    > >
    > > cm.ActiveConnection = objConn
    > >
    > > tmpRs = cm.Execute
    > >
    > > DataGrid1.DataSource = tmpRs.GetRows
    > >
    > > DataGrid1.DataBind()
    > >
    > > tmpRs.Close()
    > >
    > > tmpRs = Nothing
    > >
    > > cm = Nothing
    > >
    > > objConn.Close()
    > >
    > > objConn = Nothing
    > >
    > >

    >
    Kristoffer Arfvidson, Jan 30, 2004
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Stephen Miller
    Replies:
    2
    Views:
    5,210
    Stevie_mac
    Aug 16, 2003
  2. Jordan
    Replies:
    2
    Views:
    2,519
    Jordan
    Feb 10, 2004
  3. Neo Geshel
    Replies:
    2
    Views:
    718
    Neo Geshel
    Nov 17, 2005
  4. Replies:
    1
    Views:
    300
    =?Utf-8?B?UGV0ZXIgQnJvbWJlcmcgW0MjIE1WUF0=?=
    Mar 9, 2007
  5. Replies:
    2
    Views:
    284
Loading...

Share This Page