2
Answers

Error : ExecuteScalar Connection not initialised.

Jagjit Saini

Jagjit Saini

13y
1.8k
1
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)