records inserting after 10
public DataSet GetEmployees()
{
SqlConnection con = new SqlConnection("Data Source=.;Initial Catalog=EmpDB;User ID=sa;Password=sa");
con.Open();
SqlCommand cmd = new SqlCommand("Select count(ID) from carbookingdetails where createdon=Getdate()", con);
intCount= cmd.ExecuteScalar()
if (intCount>10)
alert("Booking is over for today");
else
{
//do Insertion Process in carbookdetails table.
}
Ravikumar GPosted Apr 24, 2013, 6:13 AM
Riddhi ValechaPosted Apr 18, 2013, 7:54 AM
What count are you looking for??
If its total number of rows, user count(*).
Eg - select count(*) from tablename;
bhuvana santhiPosted Apr 18, 2013, 7:18 AM
what value you are getting in the intcount variable after executing the query?
parthiban karnanPosted Apr 18, 2013, 6:06 AM
bhuvana santhiPosted Apr 18, 2013, 6:02 AM
bhuvana santhiPosted Apr 18, 2013, 5:39 AM
select count(id) fromdailybookings
where year(date) = year(getdate())
and month(date) = month(getdate())
and day(date) = day(getdate())
parthiban karnanPosted Apr 18, 2013, 5:35 AM
Select count(id) from JOINEES where year(id)= year(getdate()) and month(id) = month(getdate()) and day(id)=day(getdate())
bhuvana santhiPosted Apr 18, 2013, 5:29 AM
parthiban karnanPosted Apr 18, 2013, 5:25 AM
Select count(ID) from JOINEES where REGDATE=Getdate()
not getting count value
bhuvana santhiPosted Apr 18, 2013, 5:05 AM
parthiban karnanPosted Apr 18, 2013, 4:24 AM
executed the below code for restricting daily user registrants to 10..data not inserting..
protected void btnSave_Click(object sender, EventArgs e)
Riddhi ValechaPosted Apr 18, 2013, 2:05 AM
Correct statement is -
int count = convert.toint32(cmd.executescalar());
if(count>0)
{
alert("");
}
else
{
// Insertion.
}
------------
Hope this helps. If yes, do mark the answer as accepted. Please ignore the spelling mistakes.
Suthish NairPosted Apr 17, 2013, 9:43 AM
Run above query in SQL Server Management Studio and check the count.
Also try converting to int ..
int.Parse(cmd.ExecuteScalar().ToString()); or (int)cmd.ExecuteScalar();