locked
System.IndexOutOfRangeException RRS feed

  • Question

  • User-354204142 posted

    where is my mistake 

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Data.SqlClient;
    using System.Data;
    
    namespace Blood_Bank.BL
    {
    class CLS_login
    {
    public DataTable LOGIN(string ID, string PWD)
    {
    DAL.DataAccessLayer DAL = new DAL.DataAccessLayer();
    SqlParameter[] param = new SqlParameter[0];
    param[0] = new SqlParameter("@ID", SqlDbType.Char, 10);
    param[0].Value = ID;
    param[1] = new SqlParameter("@PWD", SqlDbType.Char, 10);
    param[1].Value = PWD;
    DAL.open(); 
    DataTable dt = new DataTable();
    dt = DAL.selectData("SP_LOGIN", param);
    return dt;
    
    
    }
    }
    }

    Thursday, October 1, 2015 6:44 AM

Answers

  • User-821857111 posted


    SqlParameter[] param = new SqlParameter[0];
    param[0] = new SqlParameter("@ID", SqlDbType.Char, 10);
    param[0].Value = ID;
    param[1] = new SqlParameter("@PWD", SqlDbType.Char, 10);
    param[1].Value = PWD;

    You declared an array of zero size then tried to set values of elements that don't exist in the array. Change the declaration:

    SqlParameter[] param = new SqlParameter[2];



    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, October 1, 2015 7:22 AM