Help with datatable please

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();

}
Cheers
 
C

Champika Nirosh

Hi,

I guess it would be better for you to use microsoft application block
"Microsoft.ApplicationBlocks.Data" to communicate with ur data base..

that way getting return values to your data table is done...
System.Data.DataTable tempDT = SqlHelper.ExecuteDataset( ...............

Regards,

Nirosh.
 
G

Guest

not sure exactly what you mean here. Can I not just create a datatable then
fill it and do an if statement to see if there are any rows in the
datatable?? If there are no rows then I would like the page to re-direct.

Champika Nirosh said:
Hi,

I guess it would be better for you to use microsoft application block
"Microsoft.ApplicationBlocks.Data" to communicate with ur data base..

that way getting return values to your data table is done...
System.Data.DataTable tempDT = SqlHelper.ExecuteDataset( ...............

Regards,

Nirosh.

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();

}
Cheers
 
G

Guest

hi ,
i think this ll work

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("rep_PersonChargedInCustody_PPS4",conSQL);
//DataTable dt = new DataTable();
da.SelectCommand.CommandType = CommandType.StoredProcedure;
da.SelectCommand.Parameters.Add(@IPCURN);
da.SelectCommand.Parameters.Add(@SUSPECTURN);
DataSet ds=new DataSet()
da.Fill(ds,"MyTable")
DataTable dt=ds.Tables[0];

dt.Rows.Count //will give u the count of rows

}


regards
Ansil

Stephen said:
not sure exactly what you mean here. Can I not just create a datatable then
fill it and do an if statement to see if there are any rows in the
datatable?? If there are no rows then I would like the page to re-direct.

Champika Nirosh said:
Hi,

I guess it would be better for you to use microsoft application block
"Microsoft.ApplicationBlocks.Data" to communicate with ur data base..

that way getting return values to your data table is done...
System.Data.DataTable tempDT = SqlHelper.ExecuteDataset( ...............

Regards,

Nirosh.

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();

}
Cheers
 
C

Champika Nirosh

The Data Access Application Block is a .NET component that contains
optimized data access code that will help you call stored procedures and
issue SQL text commands against a SQL Server database

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnbda/html/daab-rm.asp

Nirosh

Stephen said:
not sure exactly what you mean here. Can I not just create a datatable then
fill it and do an if statement to see if there are any rows in the
datatable?? If there are no rows then I would like the page to re-direct.

Champika Nirosh said:
Hi,

I guess it would be better for you to use microsoft application block
"Microsoft.ApplicationBlocks.Data" to communicate with ur data base..

that way getting return values to your data table is done...
System.Data.DataTable tempDT = SqlHelper.ExecuteDataset( ...............

Regards,

Nirosh.

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();

}
Cheers
 

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