Jagjit Saini

Jagjit Saini

  • NA
  • 166
  • 0

Error : ExecuteScalar Connection not initialised.

Jun 9 2011 9:44 AM
Hi

public abstract class clscon
    {
        protected SqlConnection con = new SqlConnection();
        public clscon()
        {
            con.ConnectionString = ConfigurationManager.ConnectionStrings["cn"].ConnectionString;
        }
    }

    public class clscon1 : clscon
    {
        public void OpenConnection()
        {
            con.Open();
        }
    }


public Int32 GetAuto()
    {
        nsDal.clscon1 con1 = new nsDal.clscon1();
        con1.OpenConnection();


       
        SqlCommand cmd = new SqlCommand();

        cmd.CommandText = "Select isnull(max(orgcod),0) from tborg";
        Int32 v_no = Convert.ToInt32(cmd.ExecuteScalar());
        cmd.Dispose();
        return v_no + 1;
    }



It is giving error "ExecuteScalar . Connection has not been initialised".

Answers (2)