suraj monde

suraj monde

  • NA
  • 9
  • 2k

Error occured at strored procedure

May 11 2015 9:18 AM
hi,
i am using seaparte connection class.

connection class
{
internal static string conn;
internal SqlConnection cnUniversal;
internal SqlCommand cmdUniversal;
internal SqlDataAdapter daUniversal;

public string ConnectionString
{
set { conn = value; }
}

public ConncetionClass()
{
conn = System.Configuration.ConfigurationManager.ConnectionStrings["ss"].ToString();

}
public virtual void Initialize()
{
try
{
cnUniversal = new SqlConnection(conn);
daUniversal = new SqlDataAdapter();
cmdUniversal = new SqlCommand();
cmdUniversal.CommandType = CommandType.StoredProcedure;
cmdUniversal.Connection = cnUniversal;
}

catch (Exception e)
{
ErrorLog("dbBasis initialization", e);
}
}


public virtual void Close()
{
if (cnUniversal.State != System.Data.ConnectionState.Closed)
cnUniversal.Close();
}

protected virtual void ErrorLog(string strMessage, Exception e)
{
Exception oException = new Exception(e.InnerException.Message + " \n\n Details:" + strMessage);
throw oException;
}
}




But error occured at stored procedure "Object reference not set to an instance of an object."




public class RegistrationDataAccess
{
ConncetionClass conn = new ConncetionClass();

DataTable dt = new DataTable();
string message;
public string userreg(string name, string rollno, string contactno, string emailid, string username, string password, string repassword)
{
try
{
using (conn.cnUniversal)
{

conn.cmdUniversal.CommandText = ("dbo.registraion");
conn.cmdUniversal.CommandType=CommandType.StoredProcedure;
conn.cmdUniversal.Parameters.AddWithValue("@name", name);
conn.cmdUniversal.Parameters.AddWithValue("@rollno", rollno);
conn.cmdUniversal.Parameters.AddWithValue("@contactno", contactno);
conn.cmdUniversal.Parameters.AddWithValue("@emailid", emailid);
conn.cmdUniversal.Parameters.AddWithValue("@username", username);
conn.cmdUniversal.Parameters.AddWithValue("@Passoword", password);
conn.cmdUniversal.Parameters.AddWithValue("@repassword", repassword);
conn.cmdUniversal.ExecuteNonQuery();

}
return message;

}
catch (Exception ex)
{
throw ex;
}

}

Answers (1)