为什么我想要执行添加操作,却添加不成功,系统提示我comm.ExecuteNonQuery有错误

已找到原因

string strsql = "insert into tb_goods(产品编号,产品名称,产品价格,生产日期,产品描述) values('"+Label1.Text+"','" + TextBox1.Text + "','"+TextBox3.Text +"','"+TextBox2.Text +"','"+TextBox4.Text+"')";

这行代码里,第一个括号里的“,”用的不是英文的,改为英文的就好了

现在已经好使了

using System;

using System.Collections.Generic;

using System.Linq;

using System.Web;

using System.Web.UI;

using System.Web.UI.WebControls;

using System.Data;

using System.Data.SqlClient;

public partial class _Default : System.Web.UI.Page

{

protected void Page_Load(object sender, EventArgs e)

{

SqlConnection sc = new SqlConnection("server=ZZF-COMPUTER;database=db_ASPNET;integrated security=true");

string cc = "server=ZZF-COMPUTER;database=db_ASPNET;integrated security=true";

NumService num = new NumService();

string cmdtxt = "select * from tb_goods";

string Numstr = num.ProNum(cc, cmdtxt);

this.Label1.Text = Numstr;

SqlDataAdapter Da = new SqlDataAdapter(cmdtxt, new SqlConnection(cc));

DataSet ds = new DataSet();

Da.Fill(ds);

this.GridView1.DataSource = ds;

this.GridView1.DataBind();

}

protected void Button1_Click(object sender, EventArgs e)

{

SqlConnection sc = new SqlConnection("server=ZZF-COMPUTER;database=db_ASPNET;integrated security=true");

string strsql = "insert into tb_goods(产品编号,产品名称,产品价格,生产日期,产品描述) values('"+Label1.Text+"','" + TextBox1.Text + "','"+TextBox3.Text +"','"+TextBox2.Text +"','"+TextBox4.Text+"')";

SqlCommand comm = new SqlCommand("proc_Insert", sc);

if(sc.State.Equals(ConnectionState.Closed))

{

sc.Open();

}

if(Convert.ToInt32(comm.ExecuteNonQuery())>0)

{

Response.Write("成功");

}

else

{

Response.Write("失败");

}

if (sc.State.Equals(ConnectionState.Open))

sc.Close();

}

}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Data;
using System.Data.SqlClient;

/// <summary>
/// NumService 的摘要说明
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
// 若要允许使用 ASP.NET AJAX 从脚本中调用此 Web 服务,请取消注释以下行。
// [System.Web.Script.Services.ScriptService]
public class NumService : System.Web.Services.WebService {

public NumService () {

//如果使用设计的组件,请取消注释以下行
//InitializeComponent();
}

[WebMethod]
public string HelloWorld() {
return "Hello World";
}
[WebMethod]
public string ProNum(string ConnectionString, string Cmdtxt)
{
SqlConnection Con = new SqlConnection(ConnectionString);
Con.Open();
SqlDataAdapter Da = new SqlDataAdapter(Cmdtxt, Con);
DataSet ds = new DataSet();
Da.Fill(ds);
int Num = ds.Tables[0].Rows.Count;
return "NO" + DateTime.Now.ToString("yyyyMMdd") + "BH" + Convert.ToString(Num + 1);
}
}

using System;using System.Collections.Generic;using System.Linq;using System.Web;using System.Web.UI;using System.Web.UI.WebControls;using System.Data;using System.Data.SqlClient;
public partial class _Default : System.Web.UI.Page{    protected void Page_Load(object sender, EventArgs e)    {        SqlConnection sc = new SqlConnection("server=ZZF-COMPUTER;database=db_ASPNET;integrated security=true");        string cc = "server=ZZF-COMPUTER;database=db_ASPNET;integrated security=true";        NumService num = new NumService();        string cmdtxt = "select * from tb_goods";        string Numstr = num.ProNum(cc, cmdtxt);        this.Label1.Text = Numstr;        SqlDataAdapter Da = new SqlDataAdapter(cmdtxt, new SqlConnection(cc));        DataSet ds = new DataSet();        Da.Fill(ds);        this.GridView1.DataSource = ds;        this.GridView1.DataBind();    }    protected void Button1_Click(object sender, EventArgs e)    {        SqlConnection sc = new SqlConnection("server=ZZF-COMPUTER;database=db_ASPNET;integrated security=true");        string strsql = "insert into tb_goods(产品名称,产品价格,生产日期,产品描述) values('" + TextBox1.Text + "','" + TextBox3.Text + "','"+TextBox2.Text+"','"+TextBox4.Text+"')";        SqlCommand comm = new SqlCommand("proc_Insert", sc);        if(sc.State.Equals(ConnectionState.Closed))        {            sc.Open();        }        if(Convert.ToInt32(comm.ExecuteNonQuery())>0)        {            Response.Write("成功");        }        else        {            Response.Write("失败");        }        if (sc.State.Equals(ConnectionState.Open))            sc.Close();            }}

利用Web服务生成产品编号 执行添加操作的更多相关文章

  1. 利用STM32CubeMX来生成USB_HID_Mouse工程【添加ADC】(1)

    现在原来的基础上添加ADC的功能. 现在(利用STM32CubeMX来生成USB_HID_Mouse工程)基础上新增硬件 JoyStick Shield 游戏摇杆扩展板 与STM32F103C8的连接 ...

  2. Web服务器之Nginx详解(操作部分)

    大纲 一.前言 二.Nginx 安装与配置 三.Nginx 配置文件详解 四.Nginx 命令参数 五.配置Nginx提供Web服务 六.配置Nginx的虚拟主机 七.配置Nginx的用户认证 八.配 ...

  3. hibernate for循环执行添加操作出错问题

    操作数据库使用hibernate框架 hibernate插入对象的时候,对于id唯一,数据库设置为自增的时候执行完操作后会将id赋予该对象 再次插入就会出现问题. 由于session缓存,得再研究下.

  4. 利用spring实现服务启动就自动执行某些操作的2种方式

    第一种方式,用bean的init-method属性 <bean class="com.emax.paycenter.log.LogBridge" init-method=&q ...

  5. 利用STM32CubeMX来生成USB_HID_Mouse工程【添加ADC】(2)【非dma和中断方式】

    上回讲到怎么采集一路的adc的数据,这次我们来采集两路的数据. 现在直接修改原先的代码 /* Private variables ----------------------------------- ...

  6. 利用js实现进入页面首先执行刷新操作,且只刷新一次

    让页面进行刷新,可以使用location.reload()方法,但是这种方法会让页面一直不断的刷新,这是因为当页面加载完成以后,我们让它刷新一次,那么浏览器就会重新向服务器请求数据, 界面会重新加载, ...

  7. 基于 REST 的 Web 服务:基础

    代表性状态传输(Representational State Transfer,REST)在 Web 领域已经得到了广泛的接受,是基于 SOAP 和 Web 服务描述语言(Web Services D ...

  8. GO.Web服务

    Web基础 Web服务器的一般工作原理可以简单地归纳为: 客户机浏览器通过TCP/IP协议建立到服务器的TCP连接 客户端向服务器发送HTTP协议请求包,请求服务器里的资源文档 服务器向客户机发送HT ...

  9. 25.C# 异步调用Web服务

    1.创建Web服务 1.1VS新建ASP.Net空Web应用程序 1.2添加Web服务新建项 1.3添加GetWeather方法和相关类 using System; using System.Coll ...

随机推荐

  1. JQery 动态填充数据到table 中

    说明: 1.把数据库中的数据查询出来,填充到前台的table中,注意 从数据查询出来的 属性IsNew="0"(table 行tr的属性) 2.单击“添加”按钮 新添加行追加到ta ...

  2. eclipse的maven、Scala环境搭建

    最近重新搭建了一下maven+Scala的环境,发现很多东西都不记得了,于是重新记录一遍. 嫌搭建麻烦的话也可以直接下载Scala官方做好的环境http://scala-ide.org/downloa ...

  3. Javascript学习之正则表达式详解

       什么是正则表达式(regular expreSSion) 正则表达式是一个描述字符模式的对象. 可以处理更复杂的字符串 JavaScript中的正则表达式使用RegExp对象表示 正则表达式用于 ...

  4. P1604&P1601

    [usaco2010]冲浪_slide 受到秘鲁的马丘比丘的新式水上乐园的启发,Farmer John决定也为奶牛们建一个水上乐园.当然,它最大的亮点就是新奇巨大的水上冲浪. 超级轨道包含 E (1 ...

  5. UESTC - 900 方老师炸弹 —— 割点

    题目链接:https://vjudge.net/problem/UESTC-900   方老师炸弹 Time Limit: 4000/2000MS (Java/Others)     Memory L ...

  6. SCAU 还有两个东西 —— 异或

    竞赛题 F  还有两个东西 Time Limit:400MS  Memory Limit:65535K 题型: 编程题   语言: 无限制 描述 给出n( n >= 2 )个整数,其中有 2 个 ...

  7. 整合kxmovie

    下载后发现kxmovie 直接运行是不通的,上面我们已经处理了ffmpeg部分的内容.当然了先处理ffmpeg部分.然后再复制kxmovie/kxmovie到项目中导入相应的文件. 编译报错:UIim ...

  8. linux应用之openssh server安装及配置(centos)

    安装OpenSSH Server 首先,我们搜索一下CentOS的软件库里面有没有已经定义好的SSH服务器包: $ yum search ssh ... ... openssh.x86_64 : An ...

  9. 【C/C++】malloc()

    <math.h>文件中对malloc()函数原型: _CRTIMP void *  __cdecl malloc(size_t); MSDN中对malloc()的解释: malloc re ...

  10. BZOJ_3123_[Sdoi2013]森林_主席树+启发式合并

    BZOJ_3123_[Sdoi2013]森林_主席树+启发式合并 Description Input 第一行包含一个正整数testcase,表示当前测试数据的测试点编号.保证1≤testcase≤20 ...