Connection has not initialized Properly ERROR!!!!
[green][red][black][blue]I Got One Problem while executing my WebForm:
"ExecuteReader: Connection property has not been initialized."
I am posted here my code also....
while executing ExecuteNonQuery method it shows this error!!
amazing i am already innitialize the Connection and Command string as oer my knowledge!!!!
but why his error!!!!!
public static string connstr= System.Configuration.ConfigurationSettings.AppSett ings.Get ("conn");
SqlConnection con=new SqlConnection();
public static string cmdstr=System.Configuration .ConfigurationSettings.AppSettings.Get ("cmdd");
SqlCommand cmd=new SqlCommand();
private void Page_Load(object sender, System.EventArgs e)
{
gridfill(DataGrid1 ,"");
con.ConnectionString =connstr;
}
private void Button1_Click(object sender, System.EventArgs e)
{
SqlParameter p1=new SqlParameter ("@num",SqlDbType.Int ,4,"num");
p1.Direction =ParameterDirection.Input ;
p1.Value =TextBox1.Text ;
SqlParameter p2=new SqlParameter ("@name",SqlDbType.Char ,2 ,"name");
p2.Direction =ParameterDirection.Input ;
p2.Value =TextBox2.Text ;
SqlParameter p3=new SqlParameter ("@job",SqlDbType.Char ,2,"job");
p3.Direction =ParameterDirection.Input ;
p3.Value =TextBox3.Text ;
cmd.CommandType=CommandType.StoredProcedure ;
cmd.CommandText="insert_rams";
cmd.Parameters .Add (p1);
cmd.Parameters .Add (p2);
cmd.Parameters .Add (p3);
try
{
con.Open ();
cmd.ExecuteNonQuery ();
Response.Write ("Inserted successfully...");
}
catch(Exception ex)
{
Response.Write (ex.Message );
}finally
{con.Close ();
}
giv any suggestions it gerate help full for me!!!!
thanks@@@@Ramas123
|