conn.Open();
SqlTransaction sqlTrans = null;
sqlTrans = conn.BeginTransaction();
SqlCommand cmd = new SqlCommand();
if (Request.QueryString["Mode"].ToString() == "Add")
{
cmd = new SqlCommand("USP__Details_Insert", conn);
}
else if (Request.QueryString["Mode"].ToString() == "edit")
{
cmd = new SqlCommand("USP__Details_Update", conn);
}
cmd.Connection = conn;
cmd.Transaction = sqlTrans;
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@Age", txtage.Text.Trim());
cmd.Parameters.AddWithValue("@Gender", drpgender.SelectedValue);
cmd.Parameters.AddWithValue("@Address", txtaddress.Text.Trim());
cmd.Parameters.AddWithValue("@Tel", txttel.Text.Trim());
cmd.Parameters.AddWithValue("@Mobile", txtmobile.Text.Trim());
cmd.Parameters.AddWithValue("@Native", txtnative.Text.Trim());
cmd.Parameters.AddWithValue("@Education",txtEducation.Text.Trim());
iResult =Convert.ToInt32(cmd.ExecuteScalar());
with the above code i get CommandText property has not been initialized
if i comment below i get error
Connection property has not been initialized
cmd.Connection = conn;