Simple Question: Bind DataReader to DatagGrid

S

Shapper

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
 
S

Shapper

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

Are you receiving an error or is it just blank?

:

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
 
G

Guest

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 said:
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

Are you receiving an error or is it just blank?

:

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,968
Messages
2,570,152
Members
46,697
Latest member
AugustNabo

Latest Threads

Top