首页 > Web开发 > 详细

利用Web服务生成产品编号 执行添加操作

时间:2018-12-07 19:02:47      阅读:200      评论:0      收藏:0      [点我收藏+]

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

下面是我的代码

哪位大佬可以教教我,到底哪里错了

非常感谢

 

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();

        

    }

}

 

 

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服务生成产品编号 执行添加操作

原文:https://www.cnblogs.com/zhang-1999/p/10084453.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!