1

I have javascript timer countdown with the code:

<script language="JavaScript">
TargetDate = "<% = TargetDate %>";
/*this is a property in code behind*/BackColor = "palegreen";
ForeColor = "navy";
CountActive = true;
CountStepper = -1;
LeadingZero = true;
DisplayFormat = "%%D%% Days, %%H%% Hours, %%M%% Minutes, %%S%% Seconds.";
FinishMessage = "the auction end"
</script>
<script language="JavaScript" src="countdown.js"></script>
</script>

the code behind:

public string TargetDate ()
{

    DataTable dataTable = new DataTable(); 
    using (SqlConnection connection = new SqlConnection("Server=localhost;Database=Timer;Trusted_Connectopn=True"))
    using (SqlCommand command = connection.CreateCommand())
    { 
        command.CommandText = "select * from endTime"; 
        connection.Open(); 
        SqlDataReader reader = command.ExecuteReader(); 
        dataTable.Load(reader); }
}

i get the error: 't.TargetDate()': not all code paths return value.

when i tried to write return i got another error... what means that i dont know what to do :)

0

3 Answers 3

2

Your method supposed to return string. It doesn't.

public string TargetDate

There is no return.

Use ExecuteScalar, instead of ExecuteReader.

Return the string value.

Sign up to request clarification or add additional context in comments.

Comments

0

You also have a spelling error in your connection string: Trusted_Connectopn should be Trusted_Connection

Comments

0

First of all you must return the targetdate value as string according to your function specification. You should read the datatable and return that. Something like this

public string TargetDate ()
{
    String tDate = "";
    DataTable dataTable = new DataTable(); 
    using (SqlConnection connection = new SqlConnection("Server=localhost;Database=Timer;Trusted_Connection=True"))
    using (SqlCommand command = connection.CreateCommand())
    { 
        command.CommandText = "select * from endTime"; 
        connection.Open(); 
        SqlDataReader reader = command.ExecuteReader(); 
        dataTable.Load(reader);
         tDate = dataTable.Rows[0][0].toString(); // Expecting the first row and first column
 }
return tDate;
}

Hope this helps.

2 Comments

thank you. i got error to the line: tDate = dataTable.rows[0][0]; // Expecting the first row and first column }return tDate;} the error: CS1061: 'System.Data.DataTable' does not contain a definition for 'rows' and no extension method 'rows' accepting a first argument of type 'System.Data.DataTable' could be found (are you missing a using directive or an assembly reference?)
thanks again. i editet the: tDate = dataTable.Rows[0][0].ToString(); now, there is other problem... at the aspx page, to the line: TargetDate = "<% = TargetDate %>"; the error: CS1502: The best overloaded method match for 'System.IO.TextWriter.Write(char)' has some invalid arguments..... char ?! ... oh what a code.. what now ? :) thank you !

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.