大耳朵爱被被 2016-04-15 03:48 采纳率: 62.5%
浏览 1345
已采纳

毕设急急急急:asp.net数据库访问

图片说明
提示我访问成功了(我觉得是),但是当我添加或修改时就会弹出脚本错误。如下图
图片说明
图片说明

各位大神,求帮助,我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();
}





  • 写回答

4条回答 默认 最新

  • threenewbee 2016-04-15 16:12
    关注

    string strInsert = "insert into 院系(院系编号,院系名称)values('"+strNum+"','"+strName +"')";
    你的括号是全角的,应该修改成半角,()这是全角。()这是半角。

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥50 汇编语言除法溢出问题
  • ¥65 C++实现删除N个数据列表共有的元素
  • ¥15 Visual Studio问题
  • ¥15 state显示变量是字符串形式,但是仍然红色,无法引用,并显示类型不匹配
  • ¥20 求一个html代码,有偿
  • ¥100 关于使用MATLAB中copularnd函数的问题
  • ¥20 在虚拟机的pycharm上
  • ¥15 jupyterthemes 设置完毕后没有效果
  • ¥15 matlab图像高斯低通滤波
  • ¥15 针对曲面部件的制孔路径规划,大家有什么思路吗