SP_BGTable没有参数,提供了参数

本文关键字:参数 BGTable SP | 更新日期: 2023-09-27 17:49:35

这是我的存储过程:

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER procedure [dbo].[Insert_BranchRegistration]
@branchname varchar(100),
@address nvarchar(200),
@phone bigint,
@email varchar(200),
@bloodgroup int,
@nobags int
as
INSERT INTO [dbo].[BranchRegistration]
           ([branchname]
           ,[address]
           ,[phone]
           ,[email]
           ,[bloodgroup]
           ,[nobags])
     VALUES
           (@branchname
           ,@address
           ,@phone
           ,@email
           ,@bloodgroup
           ,@nobags)
  GO 
     ALTER procedure [dbo].[SP_BGTable] as SELECT [bgid] ,[name] FROM [dbo].[BGTable] 

这是我的asp.net html代码

<%@ Page Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="BranchRegi.aspx.cs" Inherits="BloodBank.BranchRegi" %>
<asp:Content ID="BodyContent" ContentPlaceHolderID="MainContent" runat="server">
      <div class="pagecontent">
        <div class="addform">
            <asp:Button ID="BtnAdd" runat="server" CssClass="button" Text="Add" />
            <br />
              <asp:Label ID="ErrorMessage" ForeColor="Red" class="label_inv" runat="server" ></asp:Label>
            <br />
        </div>
        <div class="form">
            <div class="border-line">
                <div>
                  <span class="width">  <asp:Label ID="lblBranchName" class="label_inv" runat="server" Text="Branch Name"></asp:Label></span>
                    <span class="leftmargin">
                        <asp:TextBox ID="txtBranchName" class="textbox_body" runat="server"></asp:TextBox>
                        <asp:RequiredFieldValidator ID="RfvBranchName" runat="server" ForeColor="Red" ErrorMessage="Please enter branch name." ControlToValidate="txtBranchName"></asp:RequiredFieldValidator>
                        <asp:RegularExpressionValidator ID="rxvBranchName" runat="server"
                            ControlToValidate="txtBranchName" ErrorMessage="Only alphabets are allowed"
                            ForeColor="Red" ValidationExpression="[a-zA-Z]+"> </asp:RegularExpressionValidator></span>
                </div>
                <br />
                <div>
                  <span class="width"> <asp:Label ID="lblAddress" class="label_inv" runat="server" Text="Address"></asp:Label></span>
                  <span style="margin-left:95px"> <asp:TextBox ID="txtAddress" Style="height: 70px" class="textbox_body" runat="server" TextMode="multiLine"></asp:TextBox>
                   <asp:RequiredFieldValidator ID="RfvAddress" ForeColor="Red" runat="server" ErrorMessage="Please enter Address." ControlToValidate="txtAddress"></asp:RequiredFieldValidator>
                   <asp:RegularExpressionValidator ID="rxvAddress" runat="server"
                        ControlToValidate="txtAddress" ErrorMessage="Only alphabets are allowed"
                        ForeColor="Red" ValidationExpression="[a-zA-Z]+" > </asp:RegularExpressionValidator></span>
                 </div>
                <br />
                <div>
                     <span class="width"> <asp:Label ID="lblPhoneNumber" class="label_inv" runat="server" Text="Phone Number"></asp:Label></span>
                     <span class="leftmargin" style="margin-left:50px"> <asp:TextBox ID="txtPhonenumber" class="textbox_body" runat="server"></asp:TextBox>
                     <asp:RequiredFieldValidator ID="RfvPhonenumber" ForeColor="Red" runat="server" ErrorMessage="Please enter phone number." ControlToValidate="txtPhonenumber"></asp:RequiredFieldValidator>                 
                     <asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" 
                     ControlToValidate="txtPhonenumber" ErrorMessage="Please enter valid mobile number" 
                        ValidationExpression="[0-9]{10}"></asp:RegularExpressionValidator></span>
                   </div>
                <br />
                <div>
                     <span class="width"> <asp:Label ID="lblEmailID" class="label_inv" runat="server" Text="Email ID"></asp:Label></span>
                     <span class="leftmargin" style="margin-left:85px" ><asp:TextBox ID="txtEmailID" class="textbox_body" runat="server"></asp:TextBox>
                     <asp:RequiredFieldValidator ID="rfvEmailID" ForeColor="Red"  runat="server" ErrorMessage="Please enter email." ControlToValidate="txtEmailID"></asp:RequiredFieldValidator>
                     <asp:RegularExpressionValidator ID="RegularExpressionValidator2" 
                runat="server" ErrorMessage="Please Enter Valid Email ID"
                    ValidationGroup="vgSubmit" ControlToValidate="txtEmailID" 
                    CssClass="requiredFieldValidateStyle"
                    ForeColor="Red" 
                    ValidationExpression="'w+([-+.']'w+)*@'w+([-.]'w+)*'.'w+([-.]'w+)*">
                    </asp:RegularExpressionValidator></span>
                </div>
                <br />
                <div>
                    <span class="width"><asp:Label ID="lblGroup" class="label_inv" runat="server" Text="Blood Group"></asp:Label></span>
                    <span class="leftmargin"> 
                        <asp:DropDownList ID="ddlBlood" runat="server">
                         </asp:DropDownList>
                    <asp:RequiredFieldValidator ID="rfvBloodGroup" ForeColor="Red" runat="server" ErrorMessage="Please enter valid group name." ControlToValidate="ddlBlood"></asp:RequiredFieldValidator>
                     </span>
                </div>
                <br />
                <div>
                    <span class="width"> <asp:Label ID="lblNoBags" class="label_inv" runat="server" Text="No. of Bags"></asp:Label></span>
                    <span class="leftmargin"><asp:TextBox ID="txtNoBags" Style="margin-left: 5px" class="textbox_body" runat="server"></asp:TextBox>
                    <asp:RequiredFieldValidator ID="rfvNoBags" ForeColor="Red" runat="server" ErrorMessage="Please enter branch name." ControlToValidate="txtNoBags"></asp:RequiredFieldValidator>
                    <asp:RegularExpressionValidator id="RegularExpressionValidator4"
                   ControlToValidate="txtNoBags"
                   ValidationExpression="'d+"
                   Display="Static"
                   EnableClientScript="true"
                   ErrorMessage="Please enter numbers only"
                   runat="server"/></span>
                </div>
                <br />
                <div>
                     <span class="width" style="margin-left:200px" ><asp:Button ID="invSubmit" runat="server" Text="Submit" OnClick="invSubmit_Click" /></span>
                   <span style="margin-left:50px" >  <asp:Button ID="invReset" runat="server" Text="Reset" /></span>
                </div>
            </div>
            </div>
    </div>
    <link href="Content/site1.css" rel="stylesheet" />
    <style>
        .leftmargin 
        {
            margin-left:60px;
        }
        .width 
        {
            width:200px;
        }
    </style>
</asp:Content>

和服务器端c#代码

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;
using BloodBank.Controllers;
using BloodBank.Models;
namespace BloodBank
{
    public partial class BranchRegi : System.Web.UI.Page
    {
        #region VARIABLES
        DataSet ds = null;
        BranchRegistration objBranch;
        Operation objOperation;
        #endregion
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                filldrop();
                ddlBlood.SelectedIndex = 0;
            }
        }
        public void filldrop()
        {
            ds = SqlHelper.ExecuteDataset(Common.GetConnectionString(), CommandType.StoredProcedure, CommanName.StoredProcedures.Select_Group);
            ddlBlood.DataSource = ds;
            ddlBlood.DataTextField = "name";
            ddlBlood.DataValueField = "bgid";
            ddlBlood.DataBind();
            ddlBlood.Items.Insert(0, new ListItem("Select", "0"));
        }
        protected void invSubmit_Click(object sender, EventArgs e)
        {
            objBranch = new BranchRegistration();
            objOperation = new Operation();
            try
            {
                objBranch.branchname = txtBranchName.Text.Trim();
                objBranch.address = txtAddress.Text.Trim();
                objBranch.phone = Int64.Parse(txtPhonenumber.Text.Trim());
                objBranch.email = txtEmailID.Text.Trim();
                //Response.Write(ddlBlood.SelectedValue.ToString());
                objBranch.bloodgroup = int.Parse(ddlBlood.SelectedItem.Value);
                objBranch.nobags = int.Parse(txtNoBags.Text.Trim());
                objOperation.RegisterBranch(objBranch);
                ErrorMessage.Text = CommanName.Messages.registerSuccess;
            }
            catch (Exception)
            {
                ErrorMessage.Text = CommanName.Messages.registerUnsuccess;
            }
        }
    }
}

int iResult = SqlHelper.ExecuteNonQuery(Common.GetConnectionString(), CommandType.StoredProcedure,CommanName.StoredProcedures.Select_Group, new SqlParameter("@branchname", objBranch.branchname), new SqlParameter("@address", objBranch.address), new SqlParameter("@phone", objBranch.phone), new SqlParameter("@email", objBranch.email), new SqlParameter("@bloodgroup", objBranch.bloodgroup), new SqlParameter("@nobags", objBranch.nobags));

例外是:

过程SP_BGTable没有参数,提供了参数

SP_BGTable没有参数,提供了参数

ALTER procedure [dbo]。[SP_BGTable] as SELECT [bgid],[name] FROM [dbo].[BGTable]

这是存储过程SP_BGTable而且没有参数!但是你试图在代码中传递参数。

我想你调用了错误的程序。将其改为Insert_BranchRegistration