Simple Question: Bind DataReader to DatagGrid

Discussion in 'ASP .Net' started by Shapper, Apr 22, 2005.

  1. Shapper

    Shapper Guest

    Hello,

    I have this code to bind a DataGrid to a DataReader when page loads:
    Sub Page_Load(Sender As Object, e As EventArgs)
    dgContent.DataSource = drContent
    dgContent.DataBind()
    End Sub

    It's not working.
    What is wrong?

    Thanks,
    Miguel

    P.S: This is my DataReader Function:

    Function drContent(ByVal page As String, ByVal name As String) As
    System.Data.IDataReader

    Dim connectionString As String =
    System.Configuration.ConfigurationSettings.AppSettings("connectionString")
    Dim dbConnection As System.Data.IDbConnection = New
    System.Data.OleDb.OleDbConnection(connectionString)

    Dim queryString As String = "SELECT [t_content].* FROM
    [t_content] WHERE (([t_content].[page] = @page) AND ([t_content].[name]
    = @name))"
    Dim dbCommand As System.Data.IDbCommand = New
    System.Data.OleDb.OleDbCommand
    dbCommand.CommandText = queryString
    dbCommand.Connection = dbConnection

    Dim dbParam_page As System.Data.IDataParameter = New
    System.Data.OleDb.OleDbParameter
    dbParam_page.ParameterName = "@page"
    dbParam_page.Value = page
    dbParam_page.DbType = System.Data.DbType.String
    dbCommand.Parameters.Add(dbParam_page)
    Dim dbParam_name As System.Data.IDataParameter = New
    System.Data.OleDb.OleDbParameter
    dbParam_name.ParameterName = "@name"
    dbParam_name.Value = name
    dbParam_name.DbType = System.Data.DbType.String
    dbCommand.Parameters.Add(dbParam_name)

    dbConnection.Open
    Dim dataReader As System.Data.IDataReader =
    dbCommand.ExecuteReader(System.Data.CommandBehavior.CloseConnection)

    Return dataReader

    End Function
     
    Shapper, Apr 22, 2005
    #1
    1. Advertising

  2. Are you receiving an error or is it just blank?

    "Shapper" wrote:

    > Hello,
    >
    > I have this code to bind a DataGrid to a DataReader when page loads:
    > Sub Page_Load(Sender As Object, e As EventArgs)
    > dgContent.DataSource = drContent
    > dgContent.DataBind()
    > End Sub
    >
    > It's not working.
    > What is wrong?
    >
    > Thanks,
    > Miguel
    >
    > P.S: This is my DataReader Function:
    >
    > Function drContent(ByVal page As String, ByVal name As String) As
    > System.Data.IDataReader
    >
    > Dim connectionString As String =
    > System.Configuration.ConfigurationSettings.AppSettings("connectionString")
    > Dim dbConnection As System.Data.IDbConnection = New
    > System.Data.OleDb.OleDbConnection(connectionString)
    >
    > Dim queryString As String = "SELECT [t_content].* FROM
    > [t_content] WHERE (([t_content].[page] = @page) AND ([t_content].[name]
    > = @name))"
    > Dim dbCommand As System.Data.IDbCommand = New
    > System.Data.OleDb.OleDbCommand
    > dbCommand.CommandText = queryString
    > dbCommand.Connection = dbConnection
    >
    > Dim dbParam_page As System.Data.IDataParameter = New
    > System.Data.OleDb.OleDbParameter
    > dbParam_page.ParameterName = "@page"
    > dbParam_page.Value = page
    > dbParam_page.DbType = System.Data.DbType.String
    > dbCommand.Parameters.Add(dbParam_page)
    > Dim dbParam_name As System.Data.IDataParameter = New
    > System.Data.OleDb.OleDbParameter
    > dbParam_name.ParameterName = "@name"
    > dbParam_name.Value = name
    > dbParam_name.DbType = System.Data.DbType.String
    > dbCommand.Parameters.Add(dbParam_name)
    >
    > dbConnection.Open
    > Dim dataReader As System.Data.IDataReader =
    > dbCommand.ExecuteReader(System.Data.CommandBehavior.CloseConnection)
    >
    > Return dataReader
    >
    > End Function
    >
    >
    >
     
    =?Utf-8?B?SWFuIFN1dHRsZQ==?=, Apr 22, 2005
    #2
    1. Advertising

  3. Shapper

    Shapper Guest

    Hi,

    I am getting an Error:
    BC30455: Argument not specified for parameter 'name' of 'Public Function
    drContent(page As String, name As String) As System.Data.IDataReader'.

    In Line: dgContent.DataSource = drContent

    Miguel

    "Ian Suttle" <> wrote in message
    news::

    > Are you receiving an error or is it just blank?
    >
    > "Shapper" wrote:
    >
    >
    > > Hello,
    > >
    > > I have this code to bind a DataGrid to a DataReader when page loads:
    > > Sub Page_Load(Sender As Object, e As EventArgs)
    > > dgContent.DataSource = drContent
    > > dgContent.DataBind()
    > > End Sub
    > >
    > > It's not working.
    > > What is wrong?
    > >
    > > Thanks,
    > > Miguel
    > >
    > > P.S: This is my DataReader Function:
    > >
    > > Function drContent(ByVal page As String, ByVal name As String) As
    > > System.Data.IDataReader
    > >
    > > Dim connectionString As String =
    > > System.Configuration.ConfigurationSettings.AppSettings("connectionString")
    > > Dim dbConnection As System.Data.IDbConnection = New
    > > System.Data.OleDb.OleDbConnection(connectionString)
    > >
    > > Dim queryString As String = "SELECT [t_content].* FROM
    > > [t_content] WHERE (([t_content].[page] = @page) AND ([t_content].[name]
    > > = @name))"
    > > Dim dbCommand As System.Data.IDbCommand = New
    > > System.Data.OleDb.OleDbCommand
    > > dbCommand.CommandText = queryString
    > > dbCommand.Connection = dbConnection
    > >
    > > Dim dbParam_page As System.Data.IDataParameter = New
    > > System.Data.OleDb.OleDbParameter
    > > dbParam_page.ParameterName = "@page"
    > > dbParam_page.Value = page
    > > dbParam_page.DbType = System.Data.DbType.String
    > > dbCommand.Parameters.Add(dbParam_page)
    > > Dim dbParam_name As System.Data.IDataParameter = New
    > > System.Data.OleDb.OleDbParameter
    > > dbParam_name.ParameterName = "@name"
    > > dbParam_name.Value = name
    > > dbParam_name.DbType = System.Data.DbType.String
    > > dbCommand.Parameters.Add(dbParam_name)
    > >
    > > dbConnection.Open
    > > Dim dataReader As System.Data.IDataReader =
    > > dbCommand.ExecuteReader(System.Data.CommandBehavior.CloseConnection)
    > >
    > > Return dataReader
    > >
    > > End Function
    > >
    > >
    > >
     
    Shapper, Apr 22, 2005
    #3
  4. It's true <g>. You are just setting the source to be the function without
    giving it page and name as your function requires.

    Ian Suttle
    http://www.IanSuttle.com

    "Shapper" wrote:

    > Hi,
    >
    > I am getting an Error:
    > BC30455: Argument not specified for parameter 'name' of 'Public Function
    > drContent(page As String, name As String) As System.Data.IDataReader'.
    >
    > In Line: dgContent.DataSource = drContent
    >
    > Miguel
    >
    > "Ian Suttle" <> wrote in message
    > news::
    >
    > > Are you receiving an error or is it just blank?
    > >
    > > "Shapper" wrote:
    > >
    > >
    > > > Hello,
    > > >
    > > > I have this code to bind a DataGrid to a DataReader when page loads:
    > > > Sub Page_Load(Sender As Object, e As EventArgs)
    > > > dgContent.DataSource = drContent
    > > > dgContent.DataBind()
    > > > End Sub
    > > >
    > > > It's not working.
    > > > What is wrong?
    > > >
    > > > Thanks,
    > > > Miguel
    > > >
    > > > P.S: This is my DataReader Function:
    > > >
    > > > Function drContent(ByVal page As String, ByVal name As String) As
    > > > System.Data.IDataReader
    > > >
    > > > Dim connectionString As String =
    > > > System.Configuration.ConfigurationSettings.AppSettings("connectionString")
    > > > Dim dbConnection As System.Data.IDbConnection = New
    > > > System.Data.OleDb.OleDbConnection(connectionString)
    > > >
    > > > Dim queryString As String = "SELECT [t_content].* FROM
    > > > [t_content] WHERE (([t_content].[page] = @page) AND ([t_content].[name]
    > > > = @name))"
    > > > Dim dbCommand As System.Data.IDbCommand = New
    > > > System.Data.OleDb.OleDbCommand
    > > > dbCommand.CommandText = queryString
    > > > dbCommand.Connection = dbConnection
    > > >
    > > > Dim dbParam_page As System.Data.IDataParameter = New
    > > > System.Data.OleDb.OleDbParameter
    > > > dbParam_page.ParameterName = "@page"
    > > > dbParam_page.Value = page
    > > > dbParam_page.DbType = System.Data.DbType.String
    > > > dbCommand.Parameters.Add(dbParam_page)
    > > > Dim dbParam_name As System.Data.IDataParameter = New
    > > > System.Data.OleDb.OleDbParameter
    > > > dbParam_name.ParameterName = "@name"
    > > > dbParam_name.Value = name
    > > > dbParam_name.DbType = System.Data.DbType.String
    > > > dbCommand.Parameters.Add(dbParam_name)
    > > >
    > > > dbConnection.Open
    > > > Dim dataReader As System.Data.IDataReader =
    > > > dbCommand.ExecuteReader(System.Data.CommandBehavior.CloseConnection)
    > > >
    > > > Return dataReader
    > > >
    > > > End Function
    > > >
    > > >
    > > >

    >
    >
     
    =?Utf-8?B?SWFuIFN1dHRsZQ==?=, Apr 22, 2005
    #4
    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. John Saunders
    Replies:
    1
    Views:
    491
    VB Programmer
    Aug 12, 2003
  2. mr2_93
    Replies:
    1
    Views:
    3,601
    mr2_93
    Oct 2, 2005
  3. Replies:
    0
    Views:
    591
  4. ABHIJIT B

    DatagGrid Cascade Style Sheet CSS

    ABHIJIT B, Feb 6, 2008, in forum: ASP .Net
    Replies:
    2
    Views:
    2,335
    ABHIJIT B
    Feb 6, 2008
  5. Phil Streiff
    Replies:
    3
    Views:
    903
    Teemu Keiski
    Apr 25, 2004
Loading...

Share This Page