Question about testing for returned values

  • Thread starter Thread starter Chicagoboy27
  • Start date Start date
C

Chicagoboy27

Sorry if this is a basic question but I was wondering how to test the
data being read back from a database. I am using a datareader currently
and am not sure if that is the best route. In classic asp it went
along the lines of setting up the recordset and testing the recordset
information as it was being written. I am not sure what is it is using
asp.net though.

Here is my current scenerio

ex, I have a table that contains file extentions such as .xls, .doc,
..ppt. What I want to do is test the dataset as they are being written
and if the dataset is equal to .xls i want it to be excel..

I am new to this and am able to connect to the table but I just can
seem to get a handle on how to test the current data being retrieved to
make
any changes. like having the record be .xls and me test for that and
replace it with excel any bump in the right direction would be helpful
....
thanks in advance

currently here is the code I have so far

SqlConnection myConnection = new SqlConnection();
try
{
myConnection.ConnectionString =
ConfigurationManager.ConnectionStrings["pubsConnectionString"].ConnectionString;

string strCommand = "SELECT * FROM FILE2";
SqlCommand myCommand = new SqlCommand(strCommand,
myConnection);
myConnection.Open();


GridView2.DataSource = myCommand.ExecuteReader();



GridView2.DataBind();
}
finally
{
myConnection.Close();
}
 
What is it you are trying to accomplish?

Do you need to examine the data before doing the binding? In which case you
need to get the data into a DataTable first - this is an in memory cache of
the results. You can look at the data, and when you are ready, bind it to
the grid.

The datareader that you are using now is a readonly, forward only result
set. So once you read through it, you can't read through it again without
rerunning the query.

If you are trying to do something else, you need to be far more clear in
your question.
 
What I am trying to do is read the data from the database determine if
it meets a certain criteria if it does then write something else. Ex.
the data base contains file extentions. I want to read those file
extention and based on their returned results display something else.

classic asp logic

if (rs("file_extention") =".xls") then
something along the lines of response.write("excel")
end if

I guess what I am asking is how to read in records from a database and
test to see what the values are if they meet a certain criteria change
the value read in to something else.

What is it you are trying to accomplish?

Do you need to examine the data before doing the binding? In which case you
need to get the data into a DataTable first - this is an in memory cache of
the results. You can look at the data, and when you are ready, bind it to
the grid.

The datareader that you are using now is a readonly, forward only result
set. So once you read through it, you can't read through it again without
rerunning the query.

If you are trying to do something else, you need to be far more clear in
your question.

Chicagoboy27 said:
Sorry if this is a basic question but I was wondering how to test the
data being read back from a database. I am using a datareader currently
and am not sure if that is the best route. In classic asp it went
along the lines of setting up the recordset and testing the recordset
information as it was being written. I am not sure what is it is using
asp.net though.

Here is my current scenerio

ex, I have a table that contains file extentions such as .xls, .doc,
.ppt. What I want to do is test the dataset as they are being written
and if the dataset is equal to .xls i want it to be excel..

I am new to this and am able to connect to the table but I just can
seem to get a handle on how to test the current data being retrieved to
make
any changes. like having the record be .xls and me test for that and
replace it with excel any bump in the right direction would be helpful
...
thanks in advance

currently here is the code I have so far

SqlConnection myConnection = new SqlConnection();
try
{
myConnection.ConnectionString =
ConfigurationManager.ConnectionStrings["pubsConnectionString"].ConnectionString;

string strCommand = "SELECT * FROM FILE2";
SqlCommand myCommand = new SqlCommand(strCommand,
myConnection);
myConnection.Open();


GridView2.DataSource = myCommand.ExecuteReader();



GridView2.DataBind();
}
finally
{
myConnection.Close();
}
 
In this case your question was already answered in my post.

If you need to know how to use the DataTable, you should look at the
documentation and do a search online - tons of examples.

Chicagoboy27 said:
What I am trying to do is read the data from the database determine if
it meets a certain criteria if it does then write something else. Ex.
the data base contains file extentions. I want to read those file
extention and based on their returned results display something else.

classic asp logic

if (rs("file_extention") =".xls") then
something along the lines of response.write("excel")
end if

I guess what I am asking is how to read in records from a database and
test to see what the values are if they meet a certain criteria change
the value read in to something else.

What is it you are trying to accomplish?

Do you need to examine the data before doing the binding? In which case
you
need to get the data into a DataTable first - this is an in memory cache
of
the results. You can look at the data, and when you are ready, bind it to
the grid.

The datareader that you are using now is a readonly, forward only result
set. So once you read through it, you can't read through it again without
rerunning the query.

If you are trying to do something else, you need to be far more clear in
your question.

Chicagoboy27 said:
Sorry if this is a basic question but I was wondering how to test the
data being read back from a database. I am using a datareader currently
and am not sure if that is the best route. In classic asp it went
along the lines of setting up the recordset and testing the recordset
information as it was being written. I am not sure what is it is using
asp.net though.

Here is my current scenerio

ex, I have a table that contains file extentions such as .xls, .doc,
.ppt. What I want to do is test the dataset as they are being written
and if the dataset is equal to .xls i want it to be excel..

I am new to this and am able to connect to the table but I just can
seem to get a handle on how to test the current data being retrieved to
make
any changes. like having the record be .xls and me test for that and
replace it with excel any bump in the right direction would be helpful
...
thanks in advance

currently here is the code I have so far

SqlConnection myConnection = new SqlConnection();
try
{
myConnection.ConnectionString =
ConfigurationManager.ConnectionStrings["pubsConnectionString"].ConnectionString;

string strCommand = "SELECT * FROM FILE2";
SqlCommand myCommand = new SqlCommand(strCommand,
myConnection);
myConnection.Open();


GridView2.DataSource = myCommand.ExecuteReader();



GridView2.DataBind();
}
finally
{
myConnection.Close();
}
 
Thank you for your time I am already looking into creating datatables.
Again thank you

In this case your question was already answered in my post.

If you need to know how to use the DataTable, you should look at the
documentation and do a search online - tons of examples.

Chicagoboy27 said:
What I am trying to do is read the data from the database determine if
it meets a certain criteria if it does then write something else. Ex.
the data base contains file extentions. I want to read those file
extention and based on their returned results display something else.

classic asp logic

if (rs("file_extention") =".xls") then
something along the lines of response.write("excel")
end if

I guess what I am asking is how to read in records from a database and
test to see what the values are if they meet a certain criteria change
the value read in to something else.

What is it you are trying to accomplish?

Do you need to examine the data before doing the binding? In which case
you
need to get the data into a DataTable first - this is an in memory cache
of
the results. You can look at the data, and when you are ready, bind it to
the grid.

The datareader that you are using now is a readonly, forward only result
set. So once you read through it, you can't read through it again without
rerunning the query.

If you are trying to do something else, you need to be far more clear in
your question.

Sorry if this is a basic question but I was wondering how to test the
data being read back from a database. I am using a datareader currently
and am not sure if that is the best route. In classic asp it went
along the lines of setting up the recordset and testing the recordset
information as it was being written. I am not sure what is it is using
asp.net though.

Here is my current scenerio

ex, I have a table that contains file extentions such as .xls, .doc,
.ppt. What I want to do is test the dataset as they are being written
and if the dataset is equal to .xls i want it to be excel..

I am new to this and am able to connect to the table but I just can
seem to get a handle on how to test the current data being retrieved to
make
any changes. like having the record be .xls and me test for that and
replace it with excel any bump in the right direction would be helpful
...
thanks in advance

currently here is the code I have so far

SqlConnection myConnection = new SqlConnection();
try
{
myConnection.ConnectionString =
ConfigurationManager.ConnectionStrings["pubsConnectionString"].ConnectionString;

string strCommand = "SELECT * FROM FILE2";
SqlCommand myCommand = new SqlCommand(strCommand,
myConnection);
myConnection.Open();


GridView2.DataSource = myCommand.ExecuteReader();



GridView2.DataBind();
}
finally
{
myConnection.Close();
}
 
Is a datatable the same as a dataset? I am using asp.net 2.0


In this case your question was already answered in my post.

If you need to know how to use the DataTable, you should look at the
documentation and do a search online - tons of examples.

Chicagoboy27 said:
What I am trying to do is read the data from the database determine if
it meets a certain criteria if it does then write something else. Ex.
the data base contains file extentions. I want to read those file
extention and based on their returned results display something else.

classic asp logic

if (rs("file_extention") =".xls") then
something along the lines of response.write("excel")
end if

I guess what I am asking is how to read in records from a database and
test to see what the values are if they meet a certain criteria change
the value read in to something else.

What is it you are trying to accomplish?

Do you need to examine the data before doing the binding? In which case
you
need to get the data into a DataTable first - this is an in memory cache
of
the results. You can look at the data, and when you are ready, bind it to
the grid.

The datareader that you are using now is a readonly, forward only result
set. So once you read through it, you can't read through it again without
rerunning the query.

If you are trying to do something else, you need to be far more clear in
your question.

Sorry if this is a basic question but I was wondering how to test the
data being read back from a database. I am using a datareader currently
and am not sure if that is the best route. In classic asp it went
along the lines of setting up the recordset and testing the recordset
information as it was being written. I am not sure what is it is using
asp.net though.

Here is my current scenerio

ex, I have a table that contains file extentions such as .xls, .doc,
.ppt. What I want to do is test the dataset as they are being written
and if the dataset is equal to .xls i want it to be excel..

I am new to this and am able to connect to the table but I just can
seem to get a handle on how to test the current data being retrieved to
make
any changes. like having the record be .xls and me test for that and
replace it with excel any bump in the right direction would be helpful
...
thanks in advance

currently here is the code I have so far

SqlConnection myConnection = new SqlConnection();
try
{
myConnection.ConnectionString =
ConfigurationManager.ConnectionStrings["pubsConnectionString"].ConnectionString;

string strCommand = "SELECT * FROM FILE2";
SqlCommand myCommand = new SqlCommand(strCommand,
myConnection);
myConnection.Open();


GridView2.DataSource = myCommand.ExecuteReader();



GridView2.DataBind();
}
finally
{
myConnection.Close();
}
 
No. A dataset is an object that can contain one or more datatables. You can
use it to define relationships between tables, and so on.

However, it seems overkill for what you are doing.

Chicagoboy27 said:
Is a datatable the same as a dataset? I am using asp.net 2.0


In this case your question was already answered in my post.

If you need to know how to use the DataTable, you should look at the
documentation and do a search online - tons of examples.

Chicagoboy27 said:
What I am trying to do is read the data from the database determine if
it meets a certain criteria if it does then write something else. Ex.
the data base contains file extentions. I want to read those file
extention and based on their returned results display something else.

classic asp logic

if (rs("file_extention") =".xls") then
something along the lines of response.write("excel")
end if

I guess what I am asking is how to read in records from a database and
test to see what the values are if they meet a certain criteria change
the value read in to something else.


Marina Levit [MVP] wrote:
What is it you are trying to accomplish?

Do you need to examine the data before doing the binding? In which
case
you
need to get the data into a DataTable first - this is an in memory
cache
of
the results. You can look at the data, and when you are ready, bind it
to
the grid.

The datareader that you are using now is a readonly, forward only
result
set. So once you read through it, you can't read through it again
without
rerunning the query.

If you are trying to do something else, you need to be far more clear
in
your question.

Sorry if this is a basic question but I was wondering how to test
the
data being read back from a database. I am using a datareader
currently
and am not sure if that is the best route. In classic asp it went
along the lines of setting up the recordset and testing the
recordset
information as it was being written. I am not sure what is it is
using
asp.net though.

Here is my current scenerio

ex, I have a table that contains file extentions such as .xls, .doc,
.ppt. What I want to do is test the dataset as they are being
written
and if the dataset is equal to .xls i want it to be excel..

I am new to this and am able to connect to the table but I just can
seem to get a handle on how to test the current data being retrieved
to
make
any changes. like having the record be .xls and me test for that and
replace it with excel any bump in the right direction would be
helpful
...
thanks in advance

currently here is the code I have so far

SqlConnection myConnection = new SqlConnection();
try
{
myConnection.ConnectionString =
ConfigurationManager.ConnectionStrings["pubsConnectionString"].ConnectionString;

string strCommand = "SELECT * FROM FILE2";
SqlCommand myCommand = new SqlCommand(strCommand,
myConnection);
myConnection.Open();


GridView2.DataSource = myCommand.ExecuteReader();



GridView2.DataBind();
}
finally
{
myConnection.Close();
}
 
I having a hard time finding good documentation. Here is what I have
so far..

SqlConnection myConnection;
myConnection = new SqlConnection();

DataTable myDataTable = new DataTable();

try
{
myConnection.ConnectionString =
ConfigurationManager.ConnectionStrings["pubsConnectionString"].ConnectionString;

string strCommandText = "Select * from file2";
SqlCommand myCommand = new SqlCommand(strCommandText,
myConnection);

SqlDataAdapter myAdapter = new SqlDataAdapter();
myAdapter.SelectCommand = myCommand;
myConnection.Open();
myAdapter.Fill(myDataTable);

for(int i=0; i<=myDataTable.Rows.Count-1; i++)
{
Response.Write(myDataTable.Columns[4]. );
}
}
finally
{
myConnection.Close();
}

GridView1.DataSource = myDataTable;
GridView1.DataBind();

}
}

I am still having a hard time figuring out how to get a handle on the
individual elements prior to the bind..


No. A dataset is an object that can contain one or more datatables. You can
use it to define relationships between tables, and so on.

However, it seems overkill for what you are doing.

Chicagoboy27 said:
Is a datatable the same as a dataset? I am using asp.net 2.0


In this case your question was already answered in my post.

If you need to know how to use the DataTable, you should look at the
documentation and do a search online - tons of examples.

What I am trying to do is read the data from the database determine if
it meets a certain criteria if it does then write something else. Ex.
the data base contains file extentions. I want to read those file
extention and based on their returned results display something else.

classic asp logic

if (rs("file_extention") =".xls") then
something along the lines of response.write("excel")
end if

I guess what I am asking is how to read in records from a database and
test to see what the values are if they meet a certain criteria change
the value read in to something else.


Marina Levit [MVP] wrote:
What is it you are trying to accomplish?

Do you need to examine the data before doing the binding? In which
case
you
need to get the data into a DataTable first - this is an in memory
cache
of
the results. You can look at the data, and when you are ready, bind it
to
the grid.

The datareader that you are using now is a readonly, forward only
result
set. So once you read through it, you can't read through it again
without
rerunning the query.

If you are trying to do something else, you need to be far more clear
in
your question.

Sorry if this is a basic question but I was wondering how to test
the
data being read back from a database. I am using a datareader
currently
and am not sure if that is the best route. In classic asp it went
along the lines of setting up the recordset and testing the
recordset
information as it was being written. I am not sure what is it is
using
asp.net though.

Here is my current scenerio

ex, I have a table that contains file extentions such as .xls, .doc,
.ppt. What I want to do is test the dataset as they are being
written
and if the dataset is equal to .xls i want it to be excel..

I am new to this and am able to connect to the table but I just can
seem to get a handle on how to test the current data being retrieved
to
make
any changes. like having the record be .xls and me test for that and
replace it with excel any bump in the right direction would be
helpful
...
thanks in advance

currently here is the code I have so far

SqlConnection myConnection = new SqlConnection();
try
{
myConnection.ConnectionString =
ConfigurationManager.ConnectionStrings["pubsConnectionString"].ConnectionString;

string strCommand = "SELECT * FROM FILE2";
SqlCommand myCommand = new SqlCommand(strCommand,
myConnection);
myConnection.Open();


GridView2.DataSource = myCommand.ExecuteReader();



GridView2.DataBind();
}
finally
{
myConnection.Close();
}
 
Sorry if this is a basic question but I was wondering how to test the
data being read back from a database. I am using a datareader currently
and am not sure if that is the best route. In classic asp it went
along the lines of setting up the recordset and testing the recordset
information as it was being written. I am not sure what is it is using
asp.net though.

Here is my current scenerio

ex, I have a table that contains file extentions such as .xls, .doc,
.ppt. What I want to do is test the dataset as they are being written
and if the dataset is equal to .xls i want it to be excel..

I am new to this and am able to connect to the table but I just can
seem to get a handle on how to test the current data being retrieved to
make
any changes. like having the record be .xls and me test for that and
replace it with excel any bump in the right direction would be helpful
...
thanks in advance

currently here is the code I have so far

SqlConnection myConnection = new SqlConnection();
try
{
myConnection.ConnectionString =
ConfigurationManager.ConnectionStrings["pubsConnectionString"].ConnectionString;

string strCommand = "SELECT * FROM FILE2";
SqlCommand myCommand = new SqlCommand(strCommand,
myConnection);
myConnection.Open();




GridView2.DataSource = myCommand.ExecuteReader();

GridView2.DataBind();
}
finally
{
myConnection.Close();
}

I'm not sure I know what you are trying to accomplish here, but to determine if
any rows were returned by the DataReader you would do it like this:

dr = myCommand.ExecuteReader();

if(dr.HasRows)
{
do the things you want to do...
}
Good luck with your project,

Otis Mukinfus
http://www.arltex.com
http://www.tomchilders.com
 
Back
Top