Help needed with a datatable

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Stephen

    Help needed with a datatable

    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_ReportStar t(object sender, System.EventArg s eArgs)
    {
    //Create a Connection
    SqlConnection conSQL = new
    SqlConnection(C onfigurationSet tings.AppSettin gs["DBConnectionSt ring"]);

    //Create Parameter
    SqlParameter @IPCURN = new SqlParameter
    ("@IPCURN", System.Data.Sql DbType.BigInt);
    @IPCURN.Directi on = ParameterDirect ion.Input;
    @IPCURN.Value = IPC;

    //Create Parameter
    SqlParameter @SUSPECTURN = new SqlParameter
    ("@SUSPECTUR N", System.Data.Sql DbType.BigInt);
    @SUSPECTURN.Dir ection = ParameterDirect ion.Input;
    @SUSPECTURN.Val ue = SUSPECT;

    //Create a Command
    SqlDataAdapter da = new SqlDataAdapter( );
    //DataTable dt = new DataTable();
    da.SelectComman d = new SqlCommand();
    da.SelectComman d.Connection = conSQL;
    da.SelectComman d.CommandText = "rep_PersonChar gedInCustody_PP S4 ";
    da.SelectComman d.CommandType = CommandType.Sto redProcedure;
    da.SelectComman d.Parameters.Ad d(@IPCURN);
    da.SelectComman d.Parameters.Ad d(@SUSPECTURN);

    conSQL.Open();

    //Create a datareader
    dr = da.SelectComman d.ExecuteReader ();
    }
  • guy

    #2
    RE: Help needed with a datatable

    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" wrote:
    [color=blue]
    > 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_ReportStar t(object sender, System.EventArg s eArgs)
    > {
    > //Create a Connection
    > SqlConnection conSQL = new
    > SqlConnection(C onfigurationSet tings.AppSettin gs["DBConnectionSt ring"]);
    >
    > //Create Parameter
    > SqlParameter @IPCURN = new SqlParameter
    > ("@IPCURN", System.Data.Sql DbType.BigInt);
    > @IPCURN.Directi on = ParameterDirect ion.Input;
    > @IPCURN.Value = IPC;
    >
    > //Create Parameter
    > SqlParameter @SUSPECTURN = new SqlParameter
    > ("@SUSPECTUR N", System.Data.Sql DbType.BigInt);
    > @SUSPECTURN.Dir ection = ParameterDirect ion.Input;
    > @SUSPECTURN.Val ue = SUSPECT;
    >
    > //Create a Command
    > SqlDataAdapter da = new SqlDataAdapter( );
    > //DataTable dt = new DataTable();
    > da.SelectComman d = new SqlCommand();
    > da.SelectComman d.Connection = conSQL;
    > da.SelectComman d.CommandText = "rep_PersonChar gedInCustody_PP S4 ";
    > da.SelectComman d.CommandType = CommandType.Sto redProcedure;
    > da.SelectComman d.Parameters.Ad d(@IPCURN);
    > da.SelectComman d.Parameters.Ad d(@SUSPECTURN);
    >
    > conSQL.Open();
    >
    > //Create a datareader
    > dr = da.SelectComman d.ExecuteReader ();
    > }[/color]

    Comment

    • Stephen

      #3
      RE: Help needed with a datatable

      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" wrote:
      [color=blue]
      > 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" wrote:
      >[color=green]
      > > 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_ReportStar t(object sender, System.EventArg s eArgs)
      > > {
      > > //Create a Connection
      > > SqlConnection conSQL = new
      > > SqlConnection(C onfigurationSet tings.AppSettin gs["DBConnectionSt ring"]);
      > >
      > > //Create Parameter
      > > SqlParameter @IPCURN = new SqlParameter
      > > ("@IPCURN", System.Data.Sql DbType.BigInt);
      > > @IPCURN.Directi on = ParameterDirect ion.Input;
      > > @IPCURN.Value = IPC;
      > >
      > > //Create Parameter
      > > SqlParameter @SUSPECTURN = new SqlParameter
      > > ("@SUSPECTUR N", System.Data.Sql DbType.BigInt);
      > > @SUSPECTURN.Dir ection = ParameterDirect ion.Input;
      > > @SUSPECTURN.Val ue = SUSPECT;
      > >
      > > //Create a Command
      > > SqlDataAdapter da = new SqlDataAdapter( );
      > > //DataTable dt = new DataTable();
      > > da.SelectComman d = new SqlCommand();
      > > da.SelectComman d.Connection = conSQL;
      > > da.SelectComman d.CommandText = "rep_PersonChar gedInCustody_PP S4 ";
      > > da.SelectComman d.CommandType = CommandType.Sto redProcedure;
      > > da.SelectComman d.Parameters.Ad d(@IPCURN);
      > > da.SelectComman d.Parameters.Ad d(@SUSPECTURN);
      > >
      > > conSQL.Open();
      > >
      > > //Create a datareader
      > > dr = da.SelectComman d.ExecuteReader ();
      > > }[/color][/color]

      Comment

      • Cor Ligthert

        #4
        Re: Help needed with a datatable

        Stephen,

        A datatable has a count
        dt.rows.count

        What do you want easier?

        Cor

        "Stephen" <Stephen@discus sions.microsoft .com>
        [color=blue]
        >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" wrote:
        >[color=green]
        >> 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" wrote:
        >>[color=darkred]
        >> > 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_ReportStar t(object sender, System.EventArg s eArgs)
        >> > {
        >> > //Create a Connection
        >> > SqlConnection conSQL = new
        >> > SqlConnection(C onfigurationSet tings.AppSettin gs["DBConnectionSt ring"]);
        >> >
        >> > //Create Parameter
        >> > SqlParameter @IPCURN = new SqlParameter
        >> > ("@IPCURN", System.Data.Sql DbType.BigInt);
        >> > @IPCURN.Directi on = ParameterDirect ion.Input;
        >> > @IPCURN.Value = IPC;
        >> >
        >> > //Create Parameter
        >> > SqlParameter @SUSPECTURN = new SqlParameter
        >> > ("@SUSPECTUR N", System.Data.Sql DbType.BigInt);
        >> > @SUSPECTURN.Dir ection = ParameterDirect ion.Input;
        >> > @SUSPECTURN.Val ue = SUSPECT;
        >> >
        >> > //Create a Command
        >> > SqlDataAdapter da = new SqlDataAdapter( );
        >> > //DataTable dt = new DataTable();
        >> > da.SelectComman d = new SqlCommand();
        >> > da.SelectComman d.Connection = conSQL;
        >> > da.SelectComman d.CommandText = "rep_PersonChar gedInCustody_PP S4 ";
        >> > da.SelectComman d.CommandType = CommandType.Sto redProcedure;
        >> > da.SelectComman d.Parameters.Ad d(@IPCURN);
        >> > da.SelectComman d.Parameters.Ad d(@SUSPECTURN);
        >> >
        >> > conSQL.Open();
        >> >
        >> > //Create a datareader
        >> > dr = da.SelectComman d.ExecuteReader ();
        >> > }[/color][/color][/color]


        Comment

        • Stephen

          #5
          Re: Help needed with a datatable

          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" wrote:
          [color=blue]
          > Stephen,
          >
          > A datatable has a count
          > dt.rows.count
          >
          > What do you want easier?
          >
          > Cor
          >
          > "Stephen" <Stephen@discus sions.microsoft .com>
          >[color=green]
          > >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" wrote:
          > >[color=darkred]
          > >> 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" wrote:
          > >>
          > >> > 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_ReportStar t(object sender, System.EventArg s eArgs)
          > >> > {
          > >> > //Create a Connection
          > >> > SqlConnection conSQL = new
          > >> > SqlConnection(C onfigurationSet tings.AppSettin gs["DBConnectionSt ring"]);
          > >> >
          > >> > //Create Parameter
          > >> > SqlParameter @IPCURN = new SqlParameter
          > >> > ("@IPCURN", System.Data.Sql DbType.BigInt);
          > >> > @IPCURN.Directi on = ParameterDirect ion.Input;
          > >> > @IPCURN.Value = IPC;
          > >> >
          > >> > //Create Parameter
          > >> > SqlParameter @SUSPECTURN = new SqlParameter
          > >> > ("@SUSPECTUR N", System.Data.Sql DbType.BigInt);
          > >> > @SUSPECTURN.Dir ection = ParameterDirect ion.Input;
          > >> > @SUSPECTURN.Val ue = SUSPECT;
          > >> >
          > >> > //Create a Command
          > >> > SqlDataAdapter da = new SqlDataAdapter( );
          > >> > //DataTable dt = new DataTable();
          > >> > da.SelectComman d = new SqlCommand();
          > >> > da.SelectComman d.Connection = conSQL;
          > >> > da.SelectComman d.CommandText = "rep_PersonChar gedInCustody_PP S4 ";
          > >> > da.SelectComman d.CommandType = CommandType.Sto redProcedure;
          > >> > da.SelectComman d.Parameters.Ad d(@IPCURN);
          > >> > da.SelectComman d.Parameters.Ad d(@SUSPECTURN);
          > >> >
          > >> > conSQL.Open();
          > >> >
          > >> > //Create a datareader
          > >> > dr = da.SelectComman d.ExecuteReader ();
          > >> > }[/color][/color]
          >
          >
          >[/color]

          Comment

          • guy

            #6
            Re: Help needed with a datatable

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

            hth guy

            "Stephen" wrote:
            [color=blue]
            > 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" wrote:
            >[color=green]
            > > Stephen,
            > >
            > > A datatable has a count
            > > dt.rows.count
            > >
            > > What do you want easier?
            > >
            > > Cor
            > >
            > > "Stephen" <Stephen@discus sions.microsoft .com>
            > >[color=darkred]
            > > >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" wrote:
            > > >
            > > >> 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" wrote:
            > > >>
            > > >> > 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_ReportStar t(object sender, System.EventArg s eArgs)
            > > >> > {
            > > >> > //Create a Connection
            > > >> > SqlConnection conSQL = new
            > > >> > SqlConnection(C onfigurationSet tings.AppSettin gs["DBConnectionSt ring"]);
            > > >> >
            > > >> > //Create Parameter
            > > >> > SqlParameter @IPCURN = new SqlParameter
            > > >> > ("@IPCURN", System.Data.Sql DbType.BigInt);
            > > >> > @IPCURN.Directi on = ParameterDirect ion.Input;
            > > >> > @IPCURN.Value = IPC;
            > > >> >
            > > >> > //Create Parameter
            > > >> > SqlParameter @SUSPECTURN = new SqlParameter
            > > >> > ("@SUSPECTUR N", System.Data.Sql DbType.BigInt);
            > > >> > @SUSPECTURN.Dir ection = ParameterDirect ion.Input;
            > > >> > @SUSPECTURN.Val ue = SUSPECT;
            > > >> >
            > > >> > //Create a Command
            > > >> > SqlDataAdapter da = new SqlDataAdapter( );
            > > >> > //DataTable dt = new DataTable();
            > > >> > da.SelectComman d = new SqlCommand();
            > > >> > da.SelectComman d.Connection = conSQL;
            > > >> > da.SelectComman d.CommandText = "rep_PersonChar gedInCustody_PP S4 ";
            > > >> > da.SelectComman d.CommandType = CommandType.Sto redProcedure;
            > > >> > da.SelectComman d.Parameters.Ad d(@IPCURN);
            > > >> > da.SelectComman d.Parameters.Ad d(@SUSPECTURN);
            > > >> >
            > > >> > conSQL.Open();
            > > >> >
            > > >> > //Create a datareader
            > > >> > dr = da.SelectComman d.ExecuteReader ();
            > > >> > }[/color]
            > >
            > >
            > >[/color][/color]

            Comment

            • Cor Ligthert

              #7
              Re: Help needed with a datatable

              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_ReportStar t(object sender, System.EventArg s eArgs)
              {
              //Create a Connection
              SqlConnection conSQL = new
              SqlConnection(C onfigurationSet tings.AppSettin gs["DBConnectionSt ring"]);

              //Create Parameter
              SqlParameter @IPCURN = new SqlParameter
              ("@IPCURN", System.Data.Sql DbType.BigInt);
              @IPCURN.Directi on = ParameterDirect ion.Input;
              @IPCURN.Value = IPC;

              //Create Parameter
              SqlParameter @SUSPECTURN = new SqlParameter
              ("@SUSPECTUR N", System.Data.Sql DbType.BigInt);
              @SUSPECTURN.Dir ection = ParameterDirect ion.Input;
              @SUSPECTURN.Val ue = SUSPECT;

              //Create a Command
              SqlDataAdapter da = new SqlDataAdapter( );
              //DataTable dt = new DataTable();
              da.SelectComman d = new SqlCommand();
              da.SelectComman d.Connection = conSQL;
              da.SelectComman d.CommandText = "rep_PersonChar gedInCustody_PP S4 ";
              da.SelectComman d.CommandType = CommandType.Sto redProcedure;
              da.SelectComman d.Parameters.Ad d(@IPCURN);
              da.SelectComman d.Parameters.Ad d(@SUSPECTURN);

              //conSQL.Open(); is not needed

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

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

              Cor


              Comment

              • guy

                #8
                Re: Help needed with a datatable

                oops didnt spot it was C#
                sorry lads!

                "guy" wrote:
                [color=blue]
                > Stephen,
                > If dt.Rows.Count > 0 then
                > 'DoStuff
                > Else
                > 'DontDoStuff
                > End If
                >
                > hth guy
                >
                > "Stephen" wrote:
                >[color=green]
                > > 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" wrote:
                > >[color=darkred]
                > > > Stephen,
                > > >
                > > > A datatable has a count
                > > > dt.rows.count
                > > >
                > > > What do you want easier?
                > > >
                > > > Cor
                > > >
                > > > "Stephen" <Stephen@discus sions.microsoft .com>
                > > >
                > > > >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" wrote:
                > > > >
                > > > >> 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" wrote:
                > > > >>
                > > > >> > 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_ReportStar t(object sender, System.EventArg s eArgs)
                > > > >> > {
                > > > >> > //Create a Connection
                > > > >> > SqlConnection conSQL = new
                > > > >> > SqlConnection(C onfigurationSet tings.AppSettin gs["DBConnectionSt ring"]);
                > > > >> >
                > > > >> > //Create Parameter
                > > > >> > SqlParameter @IPCURN = new SqlParameter
                > > > >> > ("@IPCURN", System.Data.Sql DbType.BigInt);
                > > > >> > @IPCURN.Directi on = ParameterDirect ion.Input;
                > > > >> > @IPCURN.Value = IPC;
                > > > >> >
                > > > >> > //Create Parameter
                > > > >> > SqlParameter @SUSPECTURN = new SqlParameter
                > > > >> > ("@SUSPECTUR N", System.Data.Sql DbType.BigInt);
                > > > >> > @SUSPECTURN.Dir ection = ParameterDirect ion.Input;
                > > > >> > @SUSPECTURN.Val ue = SUSPECT;
                > > > >> >
                > > > >> > //Create a Command
                > > > >> > SqlDataAdapter da = new SqlDataAdapter( );
                > > > >> > //DataTable dt = new DataTable();
                > > > >> > da.SelectComman d = new SqlCommand();
                > > > >> > da.SelectComman d.Connection = conSQL;
                > > > >> > da.SelectComman d.CommandText = "rep_PersonChar gedInCustody_PP S4 ";
                > > > >> > da.SelectComman d.CommandType = CommandType.Sto redProcedure;
                > > > >> > da.SelectComman d.Parameters.Ad d(@IPCURN);
                > > > >> > da.SelectComman d.Parameters.Ad d(@SUSPECTURN);
                > > > >> >
                > > > >> > conSQL.Open();
                > > > >> >
                > > > >> > //Create a datareader
                > > > >> > dr = da.SelectComman d.ExecuteReader ();
                > > > >> > }
                > > >
                > > >
                > > >[/color][/color][/color]

                Comment

                • Cor Ligthert

                  #9
                  Re: Help needed with a datatable

                  Guy,

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

                  microsoft.publi c.dotnet.langua ges.csharp

                  Here you can give samples in every Net program code.

                  Cor
                  [color=blue]
                  > oops didnt spot it was C#
                  > sorry lads!
                  >
                  > "guy" wrote:
                  >[color=green]
                  >> Stephen,
                  >> If dt.Rows.Count > 0 then
                  >> 'DoStuff
                  >> Else
                  >> 'DontDoStuff
                  >> End If
                  >>
                  >> hth guy
                  >>
                  >> "Stephen" wrote:
                  >>[color=darkred]
                  >> > 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" wrote:
                  >> >
                  >> > > Stephen,
                  >> > >
                  >> > > A datatable has a count
                  >> > > dt.rows.count
                  >> > >
                  >> > > What do you want easier?
                  >> > >
                  >> > > Cor
                  >> > >
                  >> > > "Stephen" <Stephen@discus sions.microsoft .com>
                  >> > >
                  >> > > >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" wrote:
                  >> > > >
                  >> > > >> 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" wrote:
                  >> > > >>
                  >> > > >> > 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_ReportStar t(object sender, System.EventArg s
                  >> > > >> > eArgs)
                  >> > > >> > {
                  >> > > >> > //Create a Connection
                  >> > > >> > SqlConnection conSQL = new
                  >> > > >> > SqlConnection(C onfigurationSet tings.AppSettin gs["DBConnectionSt ring"]);
                  >> > > >> >
                  >> > > >> > //Create Parameter
                  >> > > >> > SqlParameter @IPCURN = new SqlParameter
                  >> > > >> > ("@IPCURN", System.Data.Sql DbType.BigInt);
                  >> > > >> > @IPCURN.Directi on = ParameterDirect ion.Input;
                  >> > > >> > @IPCURN.Value = IPC;
                  >> > > >> >
                  >> > > >> > //Create Parameter
                  >> > > >> > SqlParameter @SUSPECTURN = new SqlParameter
                  >> > > >> > ("@SUSPECTUR N", System.Data.Sql DbType.BigInt);
                  >> > > >> > @SUSPECTURN.Dir ection = ParameterDirect ion.Input;
                  >> > > >> > @SUSPECTURN.Val ue = SUSPECT;
                  >> > > >> >
                  >> > > >> > //Create a Command
                  >> > > >> > SqlDataAdapter da = new SqlDataAdapter( );
                  >> > > >> > //DataTable dt = new DataTable();
                  >> > > >> > da.SelectComman d = new SqlCommand();
                  >> > > >> > da.SelectComman d.Connection = conSQL;
                  >> > > >> > da.SelectComman d.CommandText = "rep_PersonChar gedInCustody_PP S4
                  >> > > >> > ";
                  >> > > >> > da.SelectComman d.CommandType = CommandType.Sto redProcedure;
                  >> > > >> > da.SelectComman d.Parameters.Ad d(@IPCURN);
                  >> > > >> > da.SelectComman d.Parameters.Ad d(@SUSPECTURN);
                  >> > > >> >
                  >> > > >> > conSQL.Open();
                  >> > > >> >
                  >> > > >> > //Create a datareader
                  >> > > >> > dr = da.SelectComman d.ExecuteReader ();
                  >> > > >> > }
                  >> > >
                  >> > >
                  >> > >[/color][/color][/color]


                  Comment

                  Working...