Not Showing Data Grid

G

Guest

Hi All,

I have an application that fetch data thru a store proc and display in a
datagrid, but after successful execution of proc the data grid is not
visible.Please go thru the following code and plz let me know what is
missing.The data grid propertiy "Visible is true".

try
{
OracleDataAccess oracleDA = new OracleDataAccess("Data
Source=dsname;User ID=uid;Password=pwd");
if (oracleDA.OpenDBConnection() == false)
{
return;
}
OracleConnection oracleConn = oracleDA.DBConnection;

OracleCommand psCommand = new
OracleCommand("PKG_NAME.STORED_PROC_NAME", oracleConn);
psCommand.CommandType = CommandType.StoredProcedure;

OracleParameter param = new OracleParameter("RESULT_CURSOR",
OracleType.Cursor);
param.Direction = ParameterDirection.Output;
psCommand.Parameters.Add(param);

param = new OracleParameter("IN_DATE", OracleType.VarChar);
param.Direction = ParameterDirection.Input;
param.Value = txtBoxBeginDate.Text;
psCommand.Parameters.Add(param);

// Execute command
OracleDataReader reader = psCommand.ExecuteReader();

if (!reader.HasRows)
{
reader.Close();
return;
}


OracleDataAdapter odad = new OracleDataAdapter(psCommand);

DataSet ds = new DataSet();

odad.Fill(ds);

GridView1.DataSource = ds;
GridView1.DataBind();
oracleConn.Close();
}
catch (Exception ex)
{

}

Thanks and Regards
Rinu G Pillai
 
N

Nicholas Paldino [.NET/C# MVP]

Rinu,

It seems that you are not setting the data member of the grid to point
to the table to bind to. This needs to be done for the DataGridView. If
you are using a DataGrid view, then I believe just setting the data set
should work.

Try to set the data source to the DataTable in the DataSet you just
filled.

If that doesn't work, then check to see that you are actually getting
results from the stored procedure, as that's always a possibility.

Also, if you are using the DataGridView, then make sure the
AutoGenerateColumns property is set to true, or, if it is false, make sure
you add the columns to be bound to.
 
G

Guest

Hi Nic,

Thanks a lot for your quick response.

The real problem was "AutoGenerateColumns = false" , now I changed to true
and it's working.

Nic, highly appreciate if you can show some code to do the rest of the
solution you mentioned , like
1 . set the data source to the DataTable in the DataSet

2 . setting the data member of the grid to point
to the table to bind to

3 .add the columns to be bound to

Once again thanks a lot!!!!.


Nicholas Paldino said:
Rinu,

It seems that you are not setting the data member of the grid to point
to the table to bind to. This needs to be done for the DataGridView. If
you are using a DataGrid view, then I believe just setting the data set
should work.

Try to set the data source to the DataTable in the DataSet you just
filled.

If that doesn't work, then check to see that you are actually getting
results from the stored procedure, as that's always a possibility.

Also, if you are using the DataGridView, then make sure the
AutoGenerateColumns property is set to true, or, if it is false, make sure
you add the columns to be bound to.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

"Rinu Gopalakrishna Pillai"
Hi All,

I have an application that fetch data thru a store proc and display in a
datagrid, but after successful execution of proc the data grid is not
visible.Please go thru the following code and plz let me know what is
missing.The data grid propertiy "Visible is true".

try
{
OracleDataAccess oracleDA = new OracleDataAccess("Data
Source=dsname;User ID=uid;Password=pwd");
if (oracleDA.OpenDBConnection() == false)
{
return;
}
OracleConnection oracleConn = oracleDA.DBConnection;

OracleCommand psCommand = new
OracleCommand("PKG_NAME.STORED_PROC_NAME", oracleConn);
psCommand.CommandType = CommandType.StoredProcedure;

OracleParameter param = new OracleParameter("RESULT_CURSOR",
OracleType.Cursor);
param.Direction = ParameterDirection.Output;
psCommand.Parameters.Add(param);

param = new OracleParameter("IN_DATE", OracleType.VarChar);
param.Direction = ParameterDirection.Input;
param.Value = txtBoxBeginDate.Text;
psCommand.Parameters.Add(param);

// Execute command
OracleDataReader reader = psCommand.ExecuteReader();

if (!reader.HasRows)
{
reader.Close();
return;
}


OracleDataAdapter odad = new OracleDataAdapter(psCommand);

DataSet ds = new DataSet();

odad.Fill(ds);

GridView1.DataSource = ds;
GridView1.DataBind();
oracleConn.Close();
}
catch (Exception ex)
{

}

Thanks and Regards
Rinu G Pillai
 
N

Nicholas Paldino [.NET/C# MVP]

Rinu,

If you want to bind to the data table, then you can get the table
yourself by accessing the Tables property on the DataSet. If you want to
use the DataMember property on the DataGridView, then you can set the
DataSource property to the DataSet instance and then set the DataMember
property to the name of the table, the same thing you would pass to the
string indexer for the collection returned by the Tables property.

To add the columns to bind to, you would have to call the Add method on
the DataGridViewColumnCollection which is exposed by the Columns property on
the DataGridView.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

"Rinu Gopalakrishna Pillai"
Hi Nic,

Thanks a lot for your quick response.

The real problem was "AutoGenerateColumns = false" , now I changed to true
and it's working.

Nic, highly appreciate if you can show some code to do the rest of the
solution you mentioned , like
1 . set the data source to the DataTable in the DataSet

2 . setting the data member of the grid to point
to the table to bind to

3 .add the columns to be bound to

Once again thanks a lot!!!!.


Nicholas Paldino said:
Rinu,

It seems that you are not setting the data member of the grid to
point
to the table to bind to. This needs to be done for the DataGridView. If
you are using a DataGrid view, then I believe just setting the data set
should work.

Try to set the data source to the DataTable in the DataSet you just
filled.

If that doesn't work, then check to see that you are actually getting
results from the stored procedure, as that's always a possibility.

Also, if you are using the DataGridView, then make sure the
AutoGenerateColumns property is set to true, or, if it is false, make
sure
you add the columns to be bound to.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

"Rinu Gopalakrishna Pillai"
Hi All,

I have an application that fetch data thru a store proc and display in
a
datagrid, but after successful execution of proc the data grid is not
visible.Please go thru the following code and plz let me know what is
missing.The data grid propertiy "Visible is true".

try
{
OracleDataAccess oracleDA = new OracleDataAccess("Data
Source=dsname;User ID=uid;Password=pwd");
if (oracleDA.OpenDBConnection() == false)
{
return;
}
OracleConnection oracleConn = oracleDA.DBConnection;

OracleCommand psCommand = new
OracleCommand("PKG_NAME.STORED_PROC_NAME", oracleConn);
psCommand.CommandType = CommandType.StoredProcedure;

OracleParameter param = new OracleParameter("RESULT_CURSOR",
OracleType.Cursor);
param.Direction = ParameterDirection.Output;
psCommand.Parameters.Add(param);

param = new OracleParameter("IN_DATE", OracleType.VarChar);
param.Direction = ParameterDirection.Input;
param.Value = txtBoxBeginDate.Text;
psCommand.Parameters.Add(param);

// Execute command
OracleDataReader reader = psCommand.ExecuteReader();

if (!reader.HasRows)
{
reader.Close();
return;
}


OracleDataAdapter odad = new OracleDataAdapter(psCommand);

DataSet ds = new DataSet();

odad.Fill(ds);

GridView1.DataSource = ds;
GridView1.DataBind();
oracleConn.Close();
}
catch (Exception ex)
{

}

Thanks and Regards
Rinu G Pillai
 
I

Ignacio Machin \( .NET/ C# MVP \)

Hi,

"Rinu Gopalakrishna Pillai"
Hi Nic,

Thanks a lot for your quick response.

The real problem was "AutoGenerateColumns = false" , now I changed to true
and it's working.

A more fine grained control can be obtained by using TemplateColumns
instead. Especially regarding the header text of the column.
 

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

Top