我正在使用以下代码将数据插入数据库。它既不会给出错误,也不会将数据添加到数据库中。我错过了什么吗?
列分别是和univ_regno
具有email
数据类型nvarchar(50)
protected void btnSubmit_Click(object sender, EventArgs e)
{
if (chkaccept.Checked)
{
try
{
con = new SqlConnection(ConfigurationManager.ConnectionStrings["SQL Connection String"].ConnectionString);
con.Open();
com = new SqlCommand("INSERT INTO stdtable ([univ_regno],[email]) values(@univ_regno,@email)", con);
com.Parameters.Add("@univ_regno", txtuniv.Text);
com.Parameters.Add("@email", txtemail.Text);
com.ExecuteNonQuery();
con.Close();
/*show javascript message */
Type cstype = this.GetType();
ClientScriptManager cs = Page.ClientScript;
String cstext = "alert('Record Added Successfully');";
cs.RegisterStartupScript(cstype, "PopupScript", cstext, true);
}
catch (System.Exception err)
{
Type cstype = this.GetType();
ClientScriptManager cs = Page.ClientScript;
String cstext = "alert('"+ err.Message.ToString() +" ');";
cs.RegisterStartupScript(cstype, "PopupScript", cstext, true);
}
}
else
{
Type cstype = this.GetType();
ClientScriptManager cs = Page.ClientScript;
String cstext = "alert('Not checked ');";
cs.RegisterStartupScript(cstype, "PopupScript", cstext, true);
}
}