473,789 Members | 3,123 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

}
Cheers
Nov 16 '05 #1
4 1527
Hi,

I guess it would be better for you to use microsoft application block
"Microsoft.Appl icationBlocks.D ata" to communicate with ur data base..

that way getting return values to your data table is done...
System.Data.Dat aTable tempDT = SqlHelper.Execu teDataset( ...............

Regards,

Nirosh.

"Stephen" <St*****@discus sions.microsoft .com> wrote in message
news:00******** *************** ***********@mic rosoft.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_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 ();

}
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.Appl icationBlocks.D ata" to communicate with ur data base..

that way getting return values to your data table is done...
System.Data.Dat aTable tempDT = SqlHelper.Execu teDataset( ...............

Regards,

Nirosh.

"Stephen" <St*****@discus sions.microsoft .com> wrote in message
news:00******** *************** ***********@mic rosoft.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_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 ();

}
Cheers


Nov 16 '05 #3
hi ,
i think this ll work

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( "rep_PersonChar gedInCustody_PP S4",conSQL);
//DataTable dt = new DataTable();
da.SelectComman d.CommandType = CommandType.Sto redProcedure;
da.SelectComman d.Parameters.Ad d(@IPCURN);
da.SelectComman d.Parameters.Ad d(@SUSPECTURN);
DataSet ds=new DataSet()
da.Fill(ds,"MyT able")
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.Appl icationBlocks.D ata" to communicate with ur data base..

that way getting return values to your data table is done...
System.Data.Dat aTable tempDT = SqlHelper.Execu teDataset( ...............

Regards,

Nirosh.

"Stephen" <St*****@discus sions.microsoft .com> wrote in message
news:00******** *************** ***********@mic rosoft.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_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 ();

}
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*****@discus sions.microsoft .com> wrote in message
news:92******** *************** ***********@mic rosoft.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.Appl icationBlocks.D ata" to communicate with ur data base..

that way getting return values to your data table is done...
System.Data.Dat aTable tempDT = SqlHelper.Execu teDataset( ...............

Regards,

Nirosh.

"Stephen" <St*****@discus sions.microsoft .com> wrote in message
news:00******** *************** ***********@mic rosoft.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_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 ();

}
Cheers


Nov 16 '05 #5

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

Similar topics

8
1613
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 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...
2
5143
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? Also, how can I associate all the attributes and their values of a particular element to the Name & Value columns of a datatable - to read into a datatable as well as write from the datatable to the xml element? Any help will be greatly...
6
1433
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 = 'Dani'). the problem is that i don't understanh how the ViewRowState works: i have an external form that changes the value of the dataTable.
6
2028
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 brand in a datagrid. I have this error when i select a brand from the drop down list. Blow is my code,anyone can help me to solve my error,which part of my code went wrong? Really thanx and very appreciate your help in advanced.. I have been stucked...
4
2280
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 dataSet updating lark when i realised that i think i am right back at square 1!!! Here's my scenario - i have a SQLDB and i retrieve all my data from that into a dataset and display this to a datagrid(WebForm). I have got this grid sorted and...
4
1301
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 control, that new row is not recorded (check it at the datagrid.validating event). However, if I use down arrow key to move to the next row (without keying any data) and exit, the new row is recorded in the datatable. can anyone please advise if I...
7
14154
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 combobox control to that dataview. I'm trying to filter the dataview based on values in a second table (ReportsTo) in the same dataset, and it's not working. If it's possible to do this, please help me figure out what I've done wrong and how...
1
2537
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, no errors, but NO UPDATE I have to use ODBC I just need to update a field based on a key, EMBARASSED to say days going
2
3411
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 .fill method based on the excel file, and the data is read in during the .file method, so everything happens with this one command. If I try to define a column.datatype before calling .fill I get an error because the column doesn't exist yet, if I...
0
9665
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10199
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10139
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9983
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9020
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7529
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6768
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5417
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
3
2909
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.