Sir i am new to webservices and my scenario is that i want to display records from database against email and password. but when i debug webservices i recieved error. Here is my code

 [WebMethod]
        public bool CheckLogin(string Email, string Password)
        {

            return getEmail(Email, Password);
        }


        public bool getEmail(String Email, String Password)
        {

            SqlConnection NewCon;
            NewCon = Class1.GetConnection();
            NewCon.Open();
            bool check = false;
            string pa;



            SqlCommand CheckCmd = new SqlCommand("SELECT * from RegisterUsers WHERE Email ='" + Email + "' and Password='" + Password + "'", NewCon);
            CheckCmd.CommandType = CommandType.Text;
            CheckCmd.Parameters.Add("@Email", SqlDbType.NVarChar).Value = Email;

            SqlDataReader sdr = CheckCmd.ExecuteReader();



            while (sdr.Read())
            {
                pa = sdr.GetString(8); // for Password column

                if (pa == Password)
                {
                    check = true;
                }
                break;
            }

            NewCon.Close();
            return check;
        }

Recommended Answers

All 6 Replies

System.IndexOutOfRangeException: Index was outside the bounds of the array.
at System.Data.SqlClient.SqlDataReader.CheckDataIsReady(Int32 columnIndex, Boolean allowPartiallyReadColumn, Boolean permitAsync, String methodName)
at System.Data.SqlClient.SqlDataReader.TryReadColumn(Int32 i, Boolean setTimeout, Boolean allowPartiallyReadColumn)
at System.Data.SqlClient.SqlDataReader.GetString(Int32 i)
at WebSer.WebService1.getEmail(String Email, String Password) in c:\Users\MuhammadAli\Documents\Visual Studio 2012\Projects\WebSer\WebSer\WebService1.asmx.cs:line 162
at WebSer.WebService1.CheckLogin(String Email, String Password) in c:\Users\MuhammadAli\Documents\Visual Studio 2012\Projects\WebSer\WebSer\WebService1.asmx.cs:line 137

i recieved this error

Index was outside the bounds of the array

 pa = sdr.GetString(8); // for Password column

Are you sure the index is 8? It starts counting at 0.

This XML file does not appear to have any style information associated with it. The document tree is shown below.
<boolean xmlns="http://tempuri.org/">false</boolean>

when i debug web services it gives me False rather than records against SQL QUERY

My scenario is that i want to get record from database against SQL Query.

SELECT * from RegisterUsers WHERE Email ='" + Email +'"

Actually we are making and android application and Web Application, when a user login via Android application the Query pass via web services and get details from SQL Server Database

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.