Read from a SP

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I need the code to read from a stored procedure not a table. I put the name
of the stored procedure where the table name "customer" is but error occurred.

int numCols = _dataSet.Tables["customers"].Columns.Count;
aColumnTextColumn.HeaderText =
_dataSet.Tables["customers"].Columns.ColumnName;
aColumnTextColumn.MappingName =
_dataSet.Tables["customers"].Columns.ColumnName;
 
I need the code to read from a stored procedure not a table. I put the
name
of the stored procedure where the table name "customer" is but error
occurred.

int numCols = _dataSet.Tables["customers"].Columns.Count;
aColumnTextColumn.HeaderText =
_dataSet.Tables["customers"].Columns.ColumnName;
aColumnTextColumn.MappingName =
_dataSet.Tables["customers"].Columns.ColumnName;


We're not psychic!

1) RDBMS name (and version) which contains the SP (e.g. SQL Server, Oracle,
mySQL, Sybase etc)

2) Database access technology (e.g. native .NET data provider, OleDb, ODBC
etc)

3) The code you used to instantiate and populate your dataSet object

4) The actual error!!!
 
Mike L said:
I need the code to read from a stored procedure not a table. I put the
name
of the stored procedure where the table name "customer" is but error
occurred.

int numCols = _dataSet.Tables["customers"].Columns.Count;
aColumnTextColumn.HeaderText =
_dataSet.Tables["customers"].Columns.ColumnName;
aColumnTextColumn.MappingName =
_dataSet.Tables["customers"].Columns.ColumnName;


By "read from a stored procedure", do you mean you need to retrieve a result
set (rows) from a stored procedure? Assuming that's what you want to do and
that you're using SQL Server, then you should be using a SqlCommand and it's
ExecuteReader method to get a DataReader object or use it in conjunction
with a SqlDataAdapter.

CVD
 
By "read from a stored procedure", do you mean you need to retrieve a
result
set (rows) from a stored procedure? Assuming that's what you want to do
and
that you're using SQL Server, then you should be using a SqlCommand and
it's
ExecuteReader method to get a DataReader object or use it in conjunction
with a SqlDataAdapter.
That would work, but you can also use ExecuteNonReader() and read the
values from the Parameters collection.

Greetings,
Wessel
 
I figured it out own my own. Replacing the SP name with a zero.

int numCols = ds.Tables[0].Columns.Count;
aColumnTextColumn.HeaderText = ds.Tables[0].Columns.ColumnName;
aColumnTextColumn.MappingName = ds.Tables[0].Columns.ColumnName;
 
Hi Cadel,

If you didn't set table mapping in the DataAdpater, the table name in the
table is not the one in the SQL server. So it's better to get value using
an index.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."
 
Back
Top