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

毕设急急急急: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条)

报告相同问题?

悬赏问题

  • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?