提示我访问成功了(我觉得是),但是当我添加或修改时就会弹出脚本错误。如下图
各位大神,求帮助,我qq:1263810415
``` protected void btnInsert_Click(object sender, EventArgs e) //添加院系
{
string strNum = txtNum.Text;
string strName = txtName.Text;
if (strNum .Trim ()=="")
{
Label2.Text = "院系编号不能为空!";
return;
}
string connStr = " server = 192.168.0.109; Initial Catalog = 网上选课; User ID = sa; Password = @XIAOYANG1314";
System.Data.SqlClient.SqlConnection conn = new System.Data.SqlClient.SqlConnection(connStr);
conn.Open();
string strSelect = "select count(*)from 院系 where 院系编号='" + strNum+ "'";
System.Data.SqlClient.SqlCommand selectCom = new System.Data.SqlClient.SqlCommand(strSelect, conn);
int count = int.Parse(selectCom.ExecuteScalar().ToString());
if (count > 0)
{
Label2.Text = "院系编号已存在!";
}
else
{
string strInsert = "insert into 院系(院系编号,院系名称)values('"+strNum+"','"+strName +"')";
System.Data.SqlClient.SqlCommand insertCom = new System.Data.SqlClient.SqlCommand(strInsert, conn);
insertCom.ExecuteNonQuery();
Label2.Text = "院系添加成功!";
}
conn.Close();
}
。