Help needed with a datatable

G

Guest

I am trying to add some code to below to include a datatable and fill the
datatable. The reason for doing this is so as I can check to see whether
there are any rows returned by the stored procedure. If there are no records
returned then this would give me an indicator and I can re-direct the page
somewhere more appropriate. Well this is the theory. I have never used
datatables before and am not sure how to implemenet what I want so I was
wondering if someone could help me please. I basically just need a datatable
and then fill the datatable with my record set. Thanks for any help anyone
can give me.

private static SqlDataReader dr;

private void PPS4_ReportStart(object sender, System.EventArgs eArgs)
{
//Create a Connection
SqlConnection conSQL = new
SqlConnection(ConfigurationSettings.AppSettings["DBConnectionString"]);

//Create Parameter
SqlParameter @IPCURN = new SqlParameter
("@IPCURN", System.Data.SqlDbType.BigInt);
@IPCURN.Direction = ParameterDirection.Input;
@IPCURN.Value = IPC;

//Create Parameter
SqlParameter @SUSPECTURN = new SqlParameter
("@SUSPECTURN", System.Data.SqlDbType.BigInt);
@SUSPECTURN.Direction = ParameterDirection.Input;
@SUSPECTURN.Value = SUSPECT;

//Create a Command
SqlDataAdapter da = new SqlDataAdapter();
//DataTable dt = new DataTable();
da.SelectCommand = new SqlCommand();
da.SelectCommand.Connection = conSQL;
da.SelectCommand.CommandText = "rep_PersonChargedInCustody_PPS4 ";
da.SelectCommand.CommandType = CommandType.StoredProcedure;
da.SelectCommand.Parameters.Add(@IPCURN);
da.SelectCommand.Parameters.Add(@SUSPECTURN);

conSQL.Open();

//Create a datareader
dr = da.SelectCommand.ExecuteReader();
}
 
G

Guest

hi Stephen
dont use a datareader,

just use:-
da.Fill(dt)

providing the parameters, connection, CommandText etc are ok thats all you
need

hth
guy
 
G

Guest

I need to use a datareader in order to read the populate the fields in my
report. Using active reports you see and I need to be able to have some way
for telling when no records are returned. At the moment if there are no
records a blank report comes back but I need to be able to count the rows in
a data table and then re-direct the page if no rows are present.

guy said:
hi Stephen
dont use a datareader,

just use:-
da.Fill(dt)

providing the parameters, connection, CommandText etc are ok thats all you
need

hth
guy

Stephen said:
I am trying to add some code to below to include a datatable and fill the
datatable. The reason for doing this is so as I can check to see whether
there are any rows returned by the stored procedure. If there are no records
returned then this would give me an indicator and I can re-direct the page
somewhere more appropriate. Well this is the theory. I have never used
datatables before and am not sure how to implemenet what I want so I was
wondering if someone could help me please. I basically just need a datatable
and then fill the datatable with my record set. Thanks for any help anyone
can give me.

private static SqlDataReader dr;

private void PPS4_ReportStart(object sender, System.EventArgs eArgs)
{
//Create a Connection
SqlConnection conSQL = new
SqlConnection(ConfigurationSettings.AppSettings["DBConnectionString"]);

//Create Parameter
SqlParameter @IPCURN = new SqlParameter
("@IPCURN", System.Data.SqlDbType.BigInt);
@IPCURN.Direction = ParameterDirection.Input;
@IPCURN.Value = IPC;

//Create Parameter
SqlParameter @SUSPECTURN = new SqlParameter
("@SUSPECTURN", System.Data.SqlDbType.BigInt);
@SUSPECTURN.Direction = ParameterDirection.Input;
@SUSPECTURN.Value = SUSPECT;

//Create a Command
SqlDataAdapter da = new SqlDataAdapter();
//DataTable dt = new DataTable();
da.SelectCommand = new SqlCommand();
da.SelectCommand.Connection = conSQL;
da.SelectCommand.CommandText = "rep_PersonChargedInCustody_PPS4 ";
da.SelectCommand.CommandType = CommandType.StoredProcedure;
da.SelectCommand.Parameters.Add(@IPCURN);
da.SelectCommand.Parameters.Add(@SUSPECTURN);

conSQL.Open();

//Create a datareader
dr = da.SelectCommand.ExecuteReader();
}
 
C

Cor Ligthert

Stephen,

A datatable has a count
dt.rows.count

What do you want easier?

Cor

Stephen said:
I need to use a datareader in order to read the populate the fields in my
report. Using active reports you see and I need to be able to have some
way
for telling when no records are returned. At the moment if there are no
records a blank report comes back but I need to be able to count the rows
in
a data table and then re-direct the page if no rows are present.

guy said:
hi Stephen
dont use a datareader,

just use:-
da.Fill(dt)

providing the parameters, connection, CommandText etc are ok thats all
you
need

hth
guy

Stephen said:
I am trying to add some code to below to include a datatable and fill
the
datatable. The reason for doing this is so as I can check to see
whether
there are any rows returned by the stored procedure. If there are no
records
returned then this would give me an indicator and I can re-direct the
page
somewhere more appropriate. Well this is the theory. I have never used
datatables before and am not sure how to implemenet what I want so I
was
wondering if someone could help me please. I basically just need a
datatable
and then fill the datatable with my record set. Thanks for any help
anyone
can give me.

private static SqlDataReader dr;

private void PPS4_ReportStart(object sender, System.EventArgs eArgs)
{
//Create a Connection
SqlConnection conSQL = new
SqlConnection(ConfigurationSettings.AppSettings["DBConnectionString"]);

//Create Parameter
SqlParameter @IPCURN = new SqlParameter
("@IPCURN", System.Data.SqlDbType.BigInt);
@IPCURN.Direction = ParameterDirection.Input;
@IPCURN.Value = IPC;

//Create Parameter
SqlParameter @SUSPECTURN = new SqlParameter
("@SUSPECTURN", System.Data.SqlDbType.BigInt);
@SUSPECTURN.Direction = ParameterDirection.Input;
@SUSPECTURN.Value = SUSPECT;

//Create a Command
SqlDataAdapter da = new SqlDataAdapter();
//DataTable dt = new DataTable();
da.SelectCommand = new SqlCommand();
da.SelectCommand.Connection = conSQL;
da.SelectCommand.CommandText = "rep_PersonChargedInCustody_PPS4 ";
da.SelectCommand.CommandType = CommandType.StoredProcedure;
da.SelectCommand.Parameters.Add(@IPCURN);
da.SelectCommand.Parameters.Add(@SUSPECTURN);

conSQL.Open();

//Create a datareader
dr = da.SelectCommand.ExecuteReader();
}
 
G

Guest

I don;t want anything easier just need to be able to write some code which
counts the rows and if they are no rows then I need the code to re-direct the
page. Do you know the exact code which would help me do this. Sorry im very
knew to coding and am still learning so some things which may seem easy I
find quite hard, but im getting better.

Cor Ligthert said:
Stephen,

A datatable has a count
dt.rows.count

What do you want easier?

Cor

Stephen said:
I need to use a datareader in order to read the populate the fields in my
report. Using active reports you see and I need to be able to have some
way
for telling when no records are returned. At the moment if there are no
records a blank report comes back but I need to be able to count the rows
in
a data table and then re-direct the page if no rows are present.

guy said:
hi Stephen
dont use a datareader,

just use:-
da.Fill(dt)

providing the parameters, connection, CommandText etc are ok thats all
you
need

hth
guy

:

I am trying to add some code to below to include a datatable and fill
the
datatable. The reason for doing this is so as I can check to see
whether
there are any rows returned by the stored procedure. If there are no
records
returned then this would give me an indicator and I can re-direct the
page
somewhere more appropriate. Well this is the theory. I have never used
datatables before and am not sure how to implemenet what I want so I
was
wondering if someone could help me please. I basically just need a
datatable
and then fill the datatable with my record set. Thanks for any help
anyone
can give me.

private static SqlDataReader dr;

private void PPS4_ReportStart(object sender, System.EventArgs eArgs)
{
//Create a Connection
SqlConnection conSQL = new
SqlConnection(ConfigurationSettings.AppSettings["DBConnectionString"]);

//Create Parameter
SqlParameter @IPCURN = new SqlParameter
("@IPCURN", System.Data.SqlDbType.BigInt);
@IPCURN.Direction = ParameterDirection.Input;
@IPCURN.Value = IPC;

//Create Parameter
SqlParameter @SUSPECTURN = new SqlParameter
("@SUSPECTURN", System.Data.SqlDbType.BigInt);
@SUSPECTURN.Direction = ParameterDirection.Input;
@SUSPECTURN.Value = SUSPECT;

//Create a Command
SqlDataAdapter da = new SqlDataAdapter();
//DataTable dt = new DataTable();
da.SelectCommand = new SqlCommand();
da.SelectCommand.Connection = conSQL;
da.SelectCommand.CommandText = "rep_PersonChargedInCustody_PPS4 ";
da.SelectCommand.CommandType = CommandType.StoredProcedure;
da.SelectCommand.Parameters.Add(@IPCURN);
da.SelectCommand.Parameters.Add(@SUSPECTURN);

conSQL.Open();

//Create a datareader
dr = da.SelectCommand.ExecuteReader();
}
 
G

Guest

Stephen,
If dt.Rows.Count > 0 then
'DoStuff
Else
'DontDoStuff
End If

hth guy

Stephen said:
I don;t want anything easier just need to be able to write some code which
counts the rows and if they are no rows then I need the code to re-direct the
page. Do you know the exact code which would help me do this. Sorry im very
knew to coding and am still learning so some things which may seem easy I
find quite hard, but im getting better.

Cor Ligthert said:
Stephen,

A datatable has a count
dt.rows.count

What do you want easier?

Cor

Stephen said:
I need to use a datareader in order to read the populate the fields in my
report. Using active reports you see and I need to be able to have some
way
for telling when no records are returned. At the moment if there are no
records a blank report comes back but I need to be able to count the rows
in
a data table and then re-direct the page if no rows are present.

:

hi Stephen
dont use a datareader,

just use:-
da.Fill(dt)

providing the parameters, connection, CommandText etc are ok thats all
you
need

hth
guy

:

I am trying to add some code to below to include a datatable and fill
the
datatable. The reason for doing this is so as I can check to see
whether
there are any rows returned by the stored procedure. If there are no
records
returned then this would give me an indicator and I can re-direct the
page
somewhere more appropriate. Well this is the theory. I have never used
datatables before and am not sure how to implemenet what I want so I
was
wondering if someone could help me please. I basically just need a
datatable
and then fill the datatable with my record set. Thanks for any help
anyone
can give me.

private static SqlDataReader dr;

private void PPS4_ReportStart(object sender, System.EventArgs eArgs)
{
//Create a Connection
SqlConnection conSQL = new
SqlConnection(ConfigurationSettings.AppSettings["DBConnectionString"]);

//Create Parameter
SqlParameter @IPCURN = new SqlParameter
("@IPCURN", System.Data.SqlDbType.BigInt);
@IPCURN.Direction = ParameterDirection.Input;
@IPCURN.Value = IPC;

//Create Parameter
SqlParameter @SUSPECTURN = new SqlParameter
("@SUSPECTURN", System.Data.SqlDbType.BigInt);
@SUSPECTURN.Direction = ParameterDirection.Input;
@SUSPECTURN.Value = SUSPECT;

//Create a Command
SqlDataAdapter da = new SqlDataAdapter();
//DataTable dt = new DataTable();
da.SelectCommand = new SqlCommand();
da.SelectCommand.Connection = conSQL;
da.SelectCommand.CommandText = "rep_PersonChargedInCustody_PPS4 ";
da.SelectCommand.CommandType = CommandType.StoredProcedure;
da.SelectCommand.Parameters.Add(@IPCURN);
da.SelectCommand.Parameters.Add(@SUSPECTURN);

conSQL.Open();

//Create a datareader
dr = da.SelectCommand.ExecuteReader();
}
 
C

Cor Ligthert

Stephen,

I see now it is almost the complete because you had already everything in it
for the datatable. therefore I only needed to changed the first and the
last lines.

\\\\

///private static SqlDataReader dr;
private void PPS4_ReportStart(object sender, System.EventArgs eArgs)
{
//Create a Connection
SqlConnection conSQL = new
SqlConnection(ConfigurationSettings.AppSettings["DBConnectionString"]);

//Create Parameter
SqlParameter @IPCURN = new SqlParameter
("@IPCURN", System.Data.SqlDbType.BigInt);
@IPCURN.Direction = ParameterDirection.Input;
@IPCURN.Value = IPC;

//Create Parameter
SqlParameter @SUSPECTURN = new SqlParameter
("@SUSPECTURN", System.Data.SqlDbType.BigInt);
@SUSPECTURN.Direction = ParameterDirection.Input;
@SUSPECTURN.Value = SUSPECT;

//Create a Command
SqlDataAdapter da = new SqlDataAdapter();
//DataTable dt = new DataTable();
da.SelectCommand = new SqlCommand();
da.SelectCommand.Connection = conSQL;
da.SelectCommand.CommandText = "rep_PersonChargedInCustody_PPS4 ";
da.SelectCommand.CommandType = CommandType.StoredProcedure;
da.SelectCommand.Parameters.Add(@IPCURN);
da.SelectCommand.Parameters.Add(@SUSPECTURN);

//conSQL.Open(); is not needed

//Create a datareader
///da.SelectCommand.ExecuteReader(); not needed
da.Fill(dt)
If (dt.Rows.Count!=0) {Response.Redirect("Whatever");}
}

I hope this goes, do not watch typos or whatever..

Cor
 
G

Guest

oops didnt spot it was C#
sorry lads!

guy said:
Stephen,
If dt.Rows.Count > 0 then
'DoStuff
Else
'DontDoStuff
End If

hth guy

Stephen said:
I don;t want anything easier just need to be able to write some code which
counts the rows and if they are no rows then I need the code to re-direct the
page. Do you know the exact code which would help me do this. Sorry im very
knew to coding and am still learning so some things which may seem easy I
find quite hard, but im getting better.

Cor Ligthert said:
Stephen,

A datatable has a count
dt.rows.count

What do you want easier?

Cor

"Stephen" <[email protected]>

I need to use a datareader in order to read the populate the fields in my
report. Using active reports you see and I need to be able to have some
way
for telling when no records are returned. At the moment if there are no
records a blank report comes back but I need to be able to count the rows
in
a data table and then re-direct the page if no rows are present.

:

hi Stephen
dont use a datareader,

just use:-
da.Fill(dt)

providing the parameters, connection, CommandText etc are ok thats all
you
need

hth
guy

:

I am trying to add some code to below to include a datatable and fill
the
datatable. The reason for doing this is so as I can check to see
whether
there are any rows returned by the stored procedure. If there are no
records
returned then this would give me an indicator and I can re-direct the
page
somewhere more appropriate. Well this is the theory. I have never used
datatables before and am not sure how to implemenet what I want so I
was
wondering if someone could help me please. I basically just need a
datatable
and then fill the datatable with my record set. Thanks for any help
anyone
can give me.

private static SqlDataReader dr;

private void PPS4_ReportStart(object sender, System.EventArgs eArgs)
{
//Create a Connection
SqlConnection conSQL = new
SqlConnection(ConfigurationSettings.AppSettings["DBConnectionString"]);

//Create Parameter
SqlParameter @IPCURN = new SqlParameter
("@IPCURN", System.Data.SqlDbType.BigInt);
@IPCURN.Direction = ParameterDirection.Input;
@IPCURN.Value = IPC;

//Create Parameter
SqlParameter @SUSPECTURN = new SqlParameter
("@SUSPECTURN", System.Data.SqlDbType.BigInt);
@SUSPECTURN.Direction = ParameterDirection.Input;
@SUSPECTURN.Value = SUSPECT;

//Create a Command
SqlDataAdapter da = new SqlDataAdapter();
//DataTable dt = new DataTable();
da.SelectCommand = new SqlCommand();
da.SelectCommand.Connection = conSQL;
da.SelectCommand.CommandText = "rep_PersonChargedInCustody_PPS4 ";
da.SelectCommand.CommandType = CommandType.StoredProcedure;
da.SelectCommand.Parameters.Add(@IPCURN);
da.SelectCommand.Parameters.Add(@SUSPECTURN);

conSQL.Open();

//Create a datareader
dr = da.SelectCommand.ExecuteReader();
}
 
C

Cor Ligthert

Guy,

Why sorry, this is a general group, not the Csharp newsgroup, that one is

microsoft.public.dotnet.languages.csharp

Here you can give samples in every Net program code.

Cor
oops didnt spot it was C#
sorry lads!

guy said:
Stephen,
If dt.Rows.Count > 0 then
'DoStuff
Else
'DontDoStuff
End If

hth guy

Stephen said:
I don;t want anything easier just need to be able to write some code
which
counts the rows and if they are no rows then I need the code to
re-direct the
page. Do you know the exact code which would help me do this. Sorry im
very
knew to coding and am still learning so some things which may seem easy
I
find quite hard, but im getting better.

:

Stephen,

A datatable has a count
dt.rows.count

What do you want easier?

Cor

"Stephen" <[email protected]>

I need to use a datareader in order to read the populate the fields
in my
report. Using active reports you see and I need to be able to have
some
way
for telling when no records are returned. At the moment if there
are no
records a blank report comes back but I need to be able to count
the rows
in
a data table and then re-direct the page if no rows are present.

:

hi Stephen
dont use a datareader,

just use:-
da.Fill(dt)

providing the parameters, connection, CommandText etc are ok thats
all
you
need

hth
guy

:

I am trying to add some code to below to include a datatable and
fill
the
datatable. The reason for doing this is so as I can check to see
whether
there are any rows returned by the stored procedure. If there
are no
records
returned then this would give me an indicator and I can
re-direct the
page
somewhere more appropriate. Well this is the theory. I have
never used
datatables before and am not sure how to implemenet what I want
so I
was
wondering if someone could help me please. I basically just need
a
datatable
and then fill the datatable with my record set. Thanks for any
help
anyone
can give me.

private static SqlDataReader dr;

private void PPS4_ReportStart(object sender, System.EventArgs
eArgs)
{
//Create a Connection
SqlConnection conSQL = new
SqlConnection(ConfigurationSettings.AppSettings["DBConnectionString"]);

//Create Parameter
SqlParameter @IPCURN = new SqlParameter
("@IPCURN", System.Data.SqlDbType.BigInt);
@IPCURN.Direction = ParameterDirection.Input;
@IPCURN.Value = IPC;

//Create Parameter
SqlParameter @SUSPECTURN = new SqlParameter
("@SUSPECTURN", System.Data.SqlDbType.BigInt);
@SUSPECTURN.Direction = ParameterDirection.Input;
@SUSPECTURN.Value = SUSPECT;

//Create a Command
SqlDataAdapter da = new SqlDataAdapter();
//DataTable dt = new DataTable();
da.SelectCommand = new SqlCommand();
da.SelectCommand.Connection = conSQL;
da.SelectCommand.CommandText = "rep_PersonChargedInCustody_PPS4
";
da.SelectCommand.CommandType = CommandType.StoredProcedure;
da.SelectCommand.Parameters.Add(@IPCURN);
da.SelectCommand.Parameters.Add(@SUSPECTURN);

conSQL.Open();

//Create a datareader
dr = da.SelectCommand.ExecuteReader();
}
 

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