fyb1261369646 2017-11-06 09:32 采纳率: 0%
浏览 1572

asp.net(C#) cmd.ExecuteNonQuery(); '(' 附近有语法错误。

login.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.OleDb;
using System.Web.Configuration;
using System.Data;
using System.Data.SqlClient;**

public class db
{
public static string connstring = "data source=localhost; Initial Catalog=user_login; integrated security=SSPI";
public static void Dosql(string sql)
{
SqlConnection conn = new SqlConnection();
conn.ConnectionString = connstring;
conn.Open();
SqlCommand cmd = new SqlCommand(sql, conn);
cmd.ExecuteNonQuery();
conn.Close();
}
}

public partial class login : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

}
protected void Button1_Click(object sender, EventArgs e)
{
    string user_name, user_pw, real_name, title, school, department, phone_number, email;
    user_name = UserText.Text.Replace("'", "''");
    user_pw = PassText.Text.Replace("'", "''");
    real_name = NameText.Text.Replace("'", "''");
    title = TitleText.Text.Replace("'", "''");
    school = SchoolText.Text.Replace("'", "''");
    department = DepartmentText.Text.Replace("'", "''");
    phone_number = PhoneText.Text.Replace("'", "''");
    email = EmailText.Text.Replace("'", "''");

    string sql = "insert into user_info (user_name,user_pw,real_name,title,school,department,phone_number,email)values]('" + user_name + "','" + user_pw + "','" + real_name + "','" + title + "','" + school + "','" + department + "','" + phone_number + "','" + email + "')";
    db.Dosql(sql);

    Response.Write("<script language=javascript>alert('注册成功,请稍后登陆!');</script>");
}

private void CheckInput()
{
    throw new NotImplementedException();
}
protected void UserText_TextChanged(object sender, EventArgs e)
{

}

}


<?xml version="1.0"?>






providerName="System.Data.SqlClient" />

求大神指导

  • 写回答

4条回答 默认 最新

  • qq_34172030 2017-11-06 09:36
    关注

    图片说明

    评论

报告相同问题?

悬赏问题

  • ¥17 pro*C预编译“闪回查询”报错SCN不能识别
  • ¥15 微信会员卡接入微信支付商户号收款
  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?