利用Web服务生成产品编号 执行添加操作
为什么我想要执行添加操作,却添加不成功,系统提示我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服务生成产品编号 执行添加操作的更多相关文章
- 利用STM32CubeMX来生成USB_HID_Mouse工程【添加ADC】(1)
现在原来的基础上添加ADC的功能. 现在(利用STM32CubeMX来生成USB_HID_Mouse工程)基础上新增硬件 JoyStick Shield 游戏摇杆扩展板 与STM32F103C8的连接 ...
- Web服务器之Nginx详解(操作部分)
大纲 一.前言 二.Nginx 安装与配置 三.Nginx 配置文件详解 四.Nginx 命令参数 五.配置Nginx提供Web服务 六.配置Nginx的虚拟主机 七.配置Nginx的用户认证 八.配 ...
- hibernate for循环执行添加操作出错问题
操作数据库使用hibernate框架 hibernate插入对象的时候,对于id唯一,数据库设置为自增的时候执行完操作后会将id赋予该对象 再次插入就会出现问题. 由于session缓存,得再研究下.
- 利用spring实现服务启动就自动执行某些操作的2种方式
第一种方式,用bean的init-method属性 <bean class="com.emax.paycenter.log.LogBridge" init-method=&q ...
- 利用STM32CubeMX来生成USB_HID_Mouse工程【添加ADC】(2)【非dma和中断方式】
上回讲到怎么采集一路的adc的数据,这次我们来采集两路的数据. 现在直接修改原先的代码 /* Private variables ----------------------------------- ...
- 利用js实现进入页面首先执行刷新操作,且只刷新一次
让页面进行刷新,可以使用location.reload()方法,但是这种方法会让页面一直不断的刷新,这是因为当页面加载完成以后,我们让它刷新一次,那么浏览器就会重新向服务器请求数据, 界面会重新加载, ...
- 基于 REST 的 Web 服务:基础
代表性状态传输(Representational State Transfer,REST)在 Web 领域已经得到了广泛的接受,是基于 SOAP 和 Web 服务描述语言(Web Services D ...
- GO.Web服务
Web基础 Web服务器的一般工作原理可以简单地归纳为: 客户机浏览器通过TCP/IP协议建立到服务器的TCP连接 客户端向服务器发送HTTP协议请求包,请求服务器里的资源文档 服务器向客户机发送HT ...
- 25.C# 异步调用Web服务
1.创建Web服务 1.1VS新建ASP.Net空Web应用程序 1.2添加Web服务新建项 1.3添加GetWeather方法和相关类 using System; using System.Coll ...
随机推荐
- requests 中文乱码
jsUrl = 'http://www.heze.cn/qiye/index.php?a=userinfo&username={}'.format(bizQiyeId)r = requests ...
- LESS和sa
一. Sass/Scss.Less是什么? Sass (Syntactically Awesome Stylesheets)是一种动态样式语言,Sass语法属于缩排语法,比css比多出好些功能(如变量 ...
- jQuery——能够编辑的表格
版权声明:欢迎转载,请注明出处 https://blog.csdn.net/suneqing/article/details/26856635 今天学习了利用jQuery实现能够编辑的表格这个 ...
- matlab面向对象设计---类的概念和使用
代码: classdef MadgwickAHRS < handle %MADGWICKAHRS Implementation of Madgwick's IMU and AHRS algori ...
- 我所认为的KVC和KVO
引子: 为什么要写这个,只是突然一个念头闪现,说一下本人目前理解.KVC: Key-value coding,它是一种使用字符串标识符,间接访问对象属性的机制.但是关就这一 ...
- linux 网络设备,网卡配置 ,相关
网络设备,网卡配置: Eth0是物理网卡:唯一mac地址,Bcast:广播地址,MAsk:子网掩码, Lo:系统自带的回环的ip地址,可以做一些基本的测试应用,比如没有网卡就用127.0.0.1, r ...
- Gym - 100187J J - Deck Shuffling —— dfs
题目链接:http://codeforces.com/gym/100187/problem/J 题目链接:问通过洗牌器,能否将编号为x的牌子转移到第一个位置? 根据 洗牌器,我们可以知道原本在第i位置 ...
- Codeforces Round #398 (Div. 2) C. Garland —— DFS
题目链接:http://codeforces.com/contest/767/problem/C 题解:类似于提着一串葡萄,用剪刀剪两条藤,葡萄分成了三串.问怎样剪才能使三串葡萄的质量相等. 首先要做 ...
- Object.prototype.constructor
Returns a reference to the Object function that created the instance's prototype. 注意这个属性的值是函数本省的引用,而 ...
- 001-将Python源码转换为不需要环境的可执行文件
1 安装pyinstaller pip install pyinstaller #或者 pip3 install pyinstaller 2 生成打包文件 在命令行中输入 pyinstaller -F ...