im trying to send data from sidenav located in my default.aspx page to another page called addstudy.aspx . im getting the alert that the study was inserted in the database , but in fact nothing is inserted , instead , in my console im getting , 500 internal server error , any help please? my code is below
Default.aspx ( on button click)
<script type="text/javascript">
function insert() {
var xmlhttp = new XMLHttpRequest();
var anchors = document.getElementById('mySidenav').getElementsByTagName('a');
for (var i = 0; i < anchors.length; i++) {
alert(anchors[i].text);
alert(anchors[i].href);
xmlhttp.open("GET", "addnewstudy.aspx?nm=" + anchors[i].text + "&gd=" + anchors[i].href + "&opr=insert", false);
xmlhttp.send(null);
alert("New Study inserted in database");
}
}
</script>
then in my addnewstudy.aspx
SqlConnection conn = new SqlConnection("Data Source=.\\SQLEXPRESS;Initial Catalog=LLDB;Integrated Security=True;Pooling=False");
string name;
string gender;
string opr;
protected void Page_Load(object sender, EventArgs e)
{
opr = Request.QueryString["opr"].ToString();
if (opr == "insert")
{
name = Request.QueryString["nm"].ToString();
gender = Request.QueryString["gd"].ToString();
SqlCommand cmd = conn.CreateCommand();
cmd.CommandType = CommandType.Text;
cmd.CommandText = "insert into tbl_myresearches (NodeName,NodeLink) values('" + name.ToString() + "','" + gender.ToString() + "')";
cmd.ExecuteNonQuery();
cmd.Dispose();
conn.Close();
}
}