padtes 30 Junior Poster in Training

2 things I can think of: 1. What is data type of h? 2. Is the result "Hits from Admin" null if you run the query (like in SQL query analyzer or Management studio)?
I would try something like this

int iHits = 1;
 if (dr["Hits"] != DBNull.Value) {
   iHits += Convert.ToInt32(dr["Hits"]);
}
//if you need string...
string sHits = iHits.ToString();

Syntax is mostly correct c#, just check spelling / case if there is problem.

kvprajapati commented: Good suggestion. +7
padtes 30 Junior Poster in Training

it looks like you got onclick handled. This should be submitting to the same page. I was suggesting more like following:
1. Under <head> add following javascript function:

function callPage(Rowkey) {
  alert ('debug: key=' + Rowkey);
  window.location = "yourOtherPage.aspx?key=' + Rowkey;
}

2. In your current code, replace onClick part as following:

e.Item.Attributes.Add("OnClick", "javascript:callPage ('" + your_key_as_per_row + "')");

The way I have used it is in my project is one cell itself is href. You seem to be doing the whole row clickable. If your alert works, there is hope. As you would notice, "your_key_as_per_row" is your business logic, not just row number (it could be row number if logically that is sufficient).

Here is actual sample code from my project

hlnk.Attributes.Add("OnClick", "OpenWeekRpt('Reports/TestDDL.aspx?showMenu=N&periodID=" + ddlPeriod.SelectedValue
                + "&metCode=" + dr["metricsID"].ToString() + "&SRcode=" +ddlCountryRel.SelectedValue+ "')");

Here hlink is one cell.

As you would notice, there are number of things being passed in the URL (string), the URL is parameter to javascript function: OpenWeekRpt.

Hope this helps.

Traicey commented: Thanks man +2
padtes 30 Junior Poster in Training

I wouldn't rely on @@rowCount. Plus, logic for user login / email looks "liberal", one can enter valid login and invalid email. My preferred logic would be:

ALTER procedure [dbo].[users_login] (@username varchar(50),@password varchar(50),
@emailid varchar(50),@ret int output)
as
begin

set @ret=0
if @emailid <> '' or @username <> ''
begin
  select @ret=1, username,password,emailid from users 
   where ( ( username=@username and @username <> '' )or 
 ( emailid= @emailid and @emailid <> '')) and [password]=@password
end

end

Please close thread once you get good enough help.

kvprajapati commented: Good suggestion. +7
padtes 30 Junior Poster in Training

There are so many errors with these, that I don't know how to correct all of it. There are 9 instances, I got tired after 7 I have pointed for some help. Looks like this is your homework. I wonder if it is even Ok to help you. anyway here it is.

1. In line 86, your where condition has comma instead of And or OR
for ex. where AGE > 25, EMP_STATE=C Check your SQL book.

2. In line 91, what are you trying? WHERE EMP_CITY LIKE "E", GENDER In line 106, there is code like this

SELECT LAST_NAME, FIRST_NAME, FROM (EMPLOYEE,JOB_TITLE)GROUP BY STATE HAVING "C"));  
SELECT LAST_NAME, FIRST_NAME, FROM (EMPLOYEE,JOB_TITLE)GROUP BY EMP_EXEMPT_STATUS));

3. One error I see is , (comma) just before from. Unless you copy pasted code wrongly. Remove the comma.

4. In from part of statement, remove the brackets. (starting ine 102)
for ex. ... from (a,b) is wrong. use ... from a,b 5. Your select and group by do not match. You cannot select columns that are not grouped on.

6. state having "C" needs to have a boolean condition for ex. having count(*) > 1 7. line 20. column name Job title cannot have blank.

All the best.

padtes 30 Junior Poster in Training

Would you rather subtract 52 weeks from your @LastBusinessDay? Because, even if today was Wed Jan 13 2010, Last year Jan 13 is Tue. select dateadd(wk, -52, getDate()) See if this is better? If it helps lets close this thread.

padtes 30 Junior Poster in Training

Database cannot really force this (nothing simple or standard way); your programming logic should take care of this by not allowing add sea not possible unless there is country, edit sea record invalid if no country relation is given by user.
As far as database is concerned, this is good.

padtes 30 Junior Poster in Training

SELECT HomePageSectionDescr,URL FROM HomePageSectionT System.Data.SqlClient.SqlException: A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections.

Which means your database is either not installed at all or your application is trying to connect to that database with user-code / password / server name etc, that is not as per the installed database.

See if you can connect to your database using tool like query analyzer using same connection information said above.

Contact your vendor of the software you bought, for how to configure the connection information. For connection information (like server name/login name/password) you will need help from your DBA or hosting service provider of your site.

padtes 30 Junior Poster in Training

I am not sure if you are ok with one plain average: here is SQL for one student (paramter = @yourInput)

select avg(marks) 
from exam-class-section-subject-student 
where student_ID = @yourInput

if you wanted average for all sytudents

select student_ID, avg(marks) 
from exam-class-section-subject-student 
group by student_ID

and so on.. Of course there needs to be more than this in any real-life application, like getting student name or average by exam type, year (like 2009 / 2010 etc) and more where conditions.
I advise you refresh you SQL.

padtes 30 Junior Poster in Training

A quick idea (not tested)

SELECT COUNTRY,
SUM(CASE WHEN Type='SALES' THEN COST END) AS SALES,
SUM(CASE WHEN Type='Expenses' THEN COST END) AS Expenses,
SUM(CASE WHEN Type='Taxes' THEN COST END) AS Taxes,
SUM(CASE WHEN Type='Profit' THEN COST END) AS Profit,
sum(when type in ('SALES','Expenses','Taxes','Profit') then cost end) as RowTot
FROM tbl_country_costs
GROUP BY COUNTRY
WITH ROLLUP
sknake commented: that is how I would do it +14