0
This is my Default.aspx.cs 

using System;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;

public partial class _Default : System.Web.UI.Page 
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void Button1_Click(object sender, EventArgs e)
    {

        {
         bool result = false;
         result = Test.Test123(User.Text, Password.Text);

         if ((result == true))
             Response.Redirect("Test.aspx");
         else
             lblText.Text = "ERROR!";
}

        }
    }

Im trying to invoke the method inside a seperate class file.

using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Text;
using System.Security.Cryptography;

/// <summary>
/// Summary description for Test
/// </summary>
public class Test
{

    private bool Test123(String User, String Password)
    {


       SqlConnection conn = new SqlConnection(("data source=ITCU-50;integrated security=true;" + "initial catalog=Test"));

        string sqlstr = ("SELECT User, Password FROM Test WHERE User = \'" 
                    + (User + "\'"));

      SqlCommand cmd = new SqlCommand(sqlstr, conn);
        conn.Open();
        SqlDataReader dr;
        dr = cmd.ExecuteReader();

        while (dr.Read()) {
            if ((User == dr["User"].ToString()) & (Password == dr["Password"].ToString()))
            {
                 return true;
                    }

                 dr.Close();
                  conn.Close();

        } 


                }
            }

Error occurs and the error message is "Test.Test123(string, string)': not all code paths return a value.

Any kind souls out there can provide me with a solution please?

Edited by Dani: Formatting fixed

1
Contributor
1
Reply
2
Views
8 Years
Discussion Span
Last Post by ku4n
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.