473,394 Members | 1,640 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Help with datatable please

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
Nov 16 '05 #1
4 1506
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.

"Stephen" <St*****@discussions.microsoft.com> wrote in message
news:00**********************************@microsof t.com...
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

Nov 16 '05 #2
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" wrote:
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.

"Stephen" <St*****@discussions.microsoft.com> wrote in message
news:00**********************************@microsof t.com...
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


Nov 16 '05 #3
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",c onSQL);
//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" wrote:
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" wrote:
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.

"Stephen" <St*****@discussions.microsoft.com> wrote in message
news:00**********************************@microsof t.com...
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


Nov 16 '05 #4
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/de...ml/daab-rm.asp

Nirosh

"Stephen" <St*****@discussions.microsoft.com> wrote in message
news:92**********************************@microsof t.com...
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" wrote:
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.

"Stephen" <St*****@discussions.microsoft.com> wrote in message
news:00**********************************@microsof t.com...
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


Nov 16 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Stephen | last post by:
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...
2
by: Anita C | last post by:
Hi, How do I associate or map a specific column in a datatable to a particular element present in an xml document - to read into a datatable as well as write from the datatable to the xml element?...
6
by: Ubi | last post by:
hi i have a problem with System.Data.DataViewRowState. i have a ReadOnly datagrid, a dataView and a dataTable. i'm using the dataView's filter property to filter the data (firstName =...
6
by: Joey Liang via DotNetMonster.com | last post by:
Hi all, I have a drop down list which store all the different brands of product.When i selected the particular brand from the drop down list, it will display all the products with the selected...
4
by: steroche | last post by:
I would REALLY appreciate help please please please! Im sure it is probably blindingly obvious to most of you but I am totally in the dark here!I am lost - i thought i had finally figured out this...
4
by: KB | last post by:
I realised that if I use datagrid and datasource is a datatable, when I created a new row and while on that row I exit the datagrid (ie. without moving into the next row) and focus onto another...
7
by: Jeff | last post by:
Hi - For my VB.NET app, I have a SQL2K database that I use to create a dataset with multiple data tables. I've created a dataview (dvReportsTo) of one of the tables, SCPMaster, and I've bound a...
1
by: cindy | last post by:
this is the call private void Page_Load(object sender, System.EventArgs e) { OdbcConnection connection = new OdbcConnection ("DSN=PFW52"); CreateDataAdapter(connection); } this is the code,...
2
by: Ryan | last post by:
Hi all, I'm loading a datagridview from an Excel file using a dataadapter.fill() method. A few questions: 1) Is there any way to control the column datatypes? The columns are defined by the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.