大耳朵爱被被 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条)

报告相同问题?

悬赏问题

  • ¥30 Matlab打开默认名称带有/的光谱数据
  • ¥50 easyExcel模板 动态单元格合并列
  • ¥15 res.rows如何取值使用
  • ¥15 在odoo17开发环境中,怎么实现库存管理系统,或独立模块设计与AGV小车对接?开发方面应如何设计和开发?请详细解释MES或WMS在与AGV小车对接时需完成的设计和开发
  • ¥15 CSP算法实现EEG特征提取,哪一步错了?
  • ¥15 游戏盾如何溯源服务器真实ip?需要30个字。后面的字是凑数的
  • ¥15 vue3前端取消收藏的不会引用collectId
  • ¥15 delphi7 HMAC_SHA256方式加密
  • ¥15 关于#qt#的问题:我想实现qcustomplot完成坐标轴
  • ¥15 下列c语言代码为何输出了多余的空格