public partial class QuestionPage : System.Web.UI.Page
{
string scon = "Data Source=RBWORKSTATION2\\SQLEXPRESS;Initial Catalog=onlineexamdb;Integrated Security=True;MultipleActiveResultSets=true";
SqlDataAdapter da;
SqlCommand cmd;
DataSet ds;
SqlConnection con;
ArrayList myArrayList = new ArrayList();
public String ques, option1,option2,option3,option4;
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
SqlConnection con = new SqlConnection(scon);
con.Open();
da = new SqlDataAdapter("select Question,Option1,Option2,Option3,Option4 from QuestionData", con);
ds = new DataSet();
da.Fill(ds);
}
}
protected void SubmitButton_Click1(object sender, EventArgs e)
{
con = new SqlConnection(scon);
con.Open();
try
{
cmd = new SqlCommand("insert into Table_1 values(@Question,@Option1,@Option2,@Option3,@Option4) ", con);
cmd.Parameters.AddWithValue("@Question", SqlDbType.VarChar).Value = ques;
cmd.Parameters.AddWithValue("@Option1", SqlDbType.Variant).Value = option1;
cmd.Parameters.AddWithValue("@Option2", SqlDbType.Variant).Value = option2;
cmd.Parameters.AddWithValue("@Option3", SqlDbType.Variant).Value = option3;
cmd.Parameters.AddWithValue("@Option4", SqlDbType.Variant).Value = option4;
cmd.ExecuteNonQuery();
// cmd.ExecuteScalar();
//Response.Write("<script>alert('Your record is insert successfuly')</script>");
}
finally
{
if (con != null)
{
con.Close();
}
}
}
protected void fv_ItemInserted(object sender, FormViewInsertedEventArgs e)
{
try
{
ques = (fv.Row.FindControl("QuestionLabel") as Label).Text;
option1 = (fv.FindControl("CheckBox13") as CheckBox).Text;
option2 = (fv.FindControl("CheckBox14") as CheckBox).Text;
option3 = (fv.FindControl("CheckBox15") as CheckBox).Text;
option4 = (fv.FindControl("CheckBox16") as CheckBox).Text;
}
finally
{
if (con != null)
{
con.Close();
}
}
}
I am getting error on line cmd.ExecuteNonQuery();
I can not insert my data in database
please please help me................