You really need a proper query, that is the only thing worth doing.
C# i after the fact, either you will have .Count >0
HTH
--
Stephen Russell
Sr. Production Systems Programmer
CIMSgts
901.246-0159 cell
IF EXISTS(SELECT top 1 yourcoulmn from YourTable)
or something like this with fewer records
IF (SELECT count(Column1) from YourTable) > 0
Looping over DataTable instance (C#) ---
using System;
using System.Data;
class Program
{
static void Main()
{
DataTable table = GetTable(); // Get the data table.
foreach (DataRow row in table.Rows) // Loop over the rows.
{
Console.WriteLine("--- Row ---"); // Print separator.
foreach (var item in row.ItemArray) // Loop over the items.
{
Console.Write("Item: "); // Print label.
Console.WriteLine(item); // Invokes ToString abstract method.
}
}
Console.Read(); // Pause.
}
/// <summary>
/// Generates DataTable filled with patient information.
/// </summary>
static DataTable GetTable()
{
DataTable table = new DataTable(); // New data table.
table.Columns.Add("Dosage", typeof(int)); // Add five columns.
table.Columns.Add("Drug", typeof(string));
table.Columns.Add("Patient", typeof(string));
table.Columns.Add("Date", typeof(DateTime));
table.Rows.Add(15, "Abilify", "Jacob", DateTime.Now); // Add five data rows.
table.Rows.Add(40, "Accupril", "Emma", DateTime.Now);
table.Rows.Add(40, "Accutane", "Michael", DateTime.Now);
table.Rows.Add(20, "Aciphex", "Ethan", DateTime.Now);
table.Rows.Add(45, "Actos", "Emily", DateTime.Now);
return table; // Return reference.
}
}
Why? You have .Count and when it is >0 you have data.
This person seems to have never supplied any indication of sharing
code on what they were doing. When asked for a SQL statement they
went blank.
For people who want to learn they will read what is asked for and
comply. As they give more we give a lot more. But if you want us to
just do your work for you well I'll gladly help you waste all of our
time. ;->
Whatever container your data will reside in has a .Count or a .Length
check that vale and act upon its outcome.
Iterate through data is foolish. You can Linq a query when you are
dealing with complicated collections of collections.
This past weekend I saw a few of the movies and am reminded to repeat
the line. "Use the force Luke."
and type = 'p')
drop procedure CustomerInsert
go
create procedure CustomerInsert(@CustomerName varchar(10),@Address varchar(20),
@City varchar(10),@Pincode numeric(6),@Result int)
as
declare @CustomerNo int
set nocount on
if exists(select CustomerName from CustomerDetails where
CustomerName = @CustomerName)
begin
raiserror('The Customer Name already Exists',10,1)
select @Result = 2
end
else
begin
begin transaction
select @CustomerNo = max(CustomerNo)+1 from CustomerDetails
insert into CustomerDetails (CustomerNo,CustomerName,Address,City,Pincode)
values(@CustomerNo,@CustomerName,@Address,@City,@Pincode)
select @Result = 1
commit transaction
end
print @Result
set nocount off
go
exec CustomerInsert 'Viji','25,Senthil Nagar','Chennai',600005,NULL