为什么我们必须在select方法中传递id?附加信息:过程或函数'sp_neetha'需要参数'@id',这是未提供的。 [英] why we have to pass id in select methode?Additional information: Procedure or function 'sp_neetha' expects parameter '@id', which was not supplied.

查看:72
本文介绍了为什么我们必须在select方法中传递id?附加信息:过程或函数'sp_neetha'需要参数'@id',这是未提供的。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用我的绑定方法grid()中的可编辑网格,这里显示此错误是我的代码







I am trying editable grid in my bind method grid() showing this error here is my code



<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="joins.WebForm1" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>

        <br />
        <br />
        <asp:Button ID="Button6" runat="server" OnClick="Button6_Click" Text="Button" />
        <br />
        <br />
        <br />
        <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="id"  ShowFooter="True" OnRowCancelingEdit="GridView1_RowCancelingEdit" OnRowCommand="GridView1_RowCommand" OnRowDeleting="GridView1_RowDeleting" OnRowEditing="GridView1_RowEditing" OnRowUpdating="GridView1_RowUpdating">
            <Columns>
                <asp:TemplateField HeaderText="id">
                    <EditItemTemplate>
                        <asp:TextBox ID="txteditid" runat="server"></asp:TextBox>
                    </EditItemTemplate>
                    <FooterTemplate>
                        <asp:TextBox ID="txteditfooter" runat="server"></asp:TextBox>
                    </FooterTemplate>
                    <ItemTemplate>
                        <asp:Label ID="Label1" runat="server" Text='<%# Eval("id") %>'></asp:Label>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="school">
                    <EditItemTemplate>
                        <asp:TextBox ID="txteditscool" runat="server"></asp:TextBox>
                    </EditItemTemplate>
                    <FooterTemplate>
                        <asp:TextBox ID="txteditfooterschool" runat="server"></asp:TextBox>
                    </FooterTemplate>
                    <ItemTemplate>
                        <asp:Label ID="Label2" runat="server" Text='<%# Eval("school") %>'></asp:Label>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="office">
                    <EditItemTemplate>
                        <asp:TextBox ID="txteditoffs" runat="server"></asp:TextBox>
                    </EditItemTemplate>
                    <FooterTemplate>
                        <asp:TextBox ID="txteditfooter" runat="server"></asp:TextBox>
                    </FooterTemplate>
                    <ItemTemplate>
                        <asp:Label ID="Label3" runat="server" Text='<%# Eval("office") %>'></asp:Label>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="action">
                    <EditItemTemplate>
                        <asp:Button ID="Button3" runat="server" Text="update" />
                        <asp:Button ID="Button4" runat="server" Text="cancel" />
                    </EditItemTemplate>
                    <FooterTemplate>
                        <asp:Button ID="btnadd" runat="server" Text="add new row" CommandName="add" />
                    </FooterTemplate>
                    <ItemTemplate>
                        <asp:Button ID="Button1" runat="server" Text="edit" />
                        <asp:Button ID="Button2" runat="server" Text="delete" />
                    </ItemTemplate>
                </asp:TemplateField>
            </Columns>
        </asp:GridView>
        <br />
        <br />

    </div>
    </form>
</body>
</html>









c#









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;

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


            if(!IsPostBack)
            {


                grid();
            }
        }

        SqlConnection con = new SqlConnection(@"Data Source=(LocalDB)\v11.0;AttachDbFilename=D:\MyPractice\joins\joins\App_Data\Database1.mdf;Integrated Security=True");
        SqlCommand cmd = new SqlCommand();


        public void grid()
        {
            con.Open();
            cmd.Connection = con;
            cmd.CommandText = "sp_neetha";
            cmd.CommandType = CommandType.StoredProcedure;//here showing error

            cmd.Parameters.AddWithValue("@flag", "select");
            
            cmd.ExecuteNonQuery();
            
            SqlDataAdapter da = new SqlDataAdapter(cmd);
            DataTable dt=new DataTable();
            da.Fill(dt);
            con.Close();
            GridView1.DataSource = dt;
            GridView1.DataBind();

          

        }



        protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
        {
            GridView1.EditIndex = e.NewEditIndex;
            grid();
        }

        protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
        {

            int id =   Convert.ToInt32(GridView1.DataKeys[e.RowIndex].Values["id"].ToString());


            TextBox txtid = (TextBox)GridView1.Rows[e.RowIndex].FindControl("txteditid");
            TextBox txtschool = (TextBox)GridView1.Rows[e.RowIndex].FindControl("txteditscool");
            TextBox txtoffs = (TextBox)GridView1.Rows[e.RowIndex].FindControl("txtoffice");
            con.Open();
            cmd.Connection = con;
            cmd.CommandText = "sp_neetha";
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.AddWithValue("@id", txtid.Text);
            cmd.Parameters.AddWithValue("@school", txtschool.Text);
            cmd.Parameters.AddWithValue("@office", txtoffs.Text);
            cmd.Parameters.AddWithValue("@flag","update");

            cmd.ExecuteNonQuery();
            GridView1.EditIndex = -1;


        }


        protected void Button6_Click(object sender, EventArgs e)
        {
            grid();
        }

        protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {

            int id=   Convert.ToInt32(GridView1.DataKeys[e.RowIndex].Values["id"].ToString());
            con.Open();
            cmd.Connection = con;
            cmd.CommandText = "sp_neetha";
            cmd.CommandType = CommandType.StoredProcedure;
            TextBox txtid = (TextBox)GridView1.Rows[e.RowIndex].FindControl("txteditid");
            cmd.Parameters.AddWithValue("@id",txtid.Text);
            cmd.Parameters.AddWithValue("@flag", "delete");
            int result = cmd.ExecuteNonQuery();
            if (result==1)
            {

                grid();

            }


            con.Close();
      }

        protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
        {


            if(e.CommandName=="add")
            {


                TextBox txtid = (TextBox)GridView1.FooterRow.FindControl("txteditfooter");
                TextBox txtschool = (TextBox)GridView1.FooterRow.FindControl("txteditfooterschool");
                TextBox txtoffs = (TextBox)GridView1.FooterRow.FindControl("txteditfooter");
              
                con.Open();
                cmd.Connection = con;
                cmd.CommandText = "sp_neetha";
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.AddWithValue("@id", txtid.Text);
                cmd.Parameters.AddWithValue("@school", txtschool.Text);
                cmd.Parameters.AddWithValue("@office", txtoffs.Text);
                cmd.Parameters.AddWithValue("@flag", "insert");
                int result = cmd.ExecuteNonQuery();
                if(result==1)
                {

                    GridView1.EditIndex = -1;
                        grid();

                      

                }

                con.Close();




            }
        }

        protected void GridView1_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
        {
            GridView1.EditIndex = -1;
            grid();
        }



    }
}

推荐答案

请检查存储程序,其中可能包含@id参数,如果是,那么它必须要求传递参数。



更多信息,请在此处讨论您的问题,请点击以下链接。

http:/ /stackoverflow.com/questions/19703653/stored-procedure-or-function-expects-parameter-which-is-not-supplied [ ^ ]



http://stackoverflow.com/问题/ 14640094 /存储过程,或功能-预计参数 - 这此结果未SUPP撒谎 [ ^ ]



http://stackoverflow.com/questions/26674149/c-sharp-stored-procedure-or-function-expects-parameter-which-is - 未提供 [ ^ ]
please check you Store Procedure which may contains @id parameter if it's so then it must require to pass the parameter.

more information your question disscussed here please follow below link.
http://stackoverflow.com/questions/19703653/stored-procedure-or-function-expects-parameter-which-is-not-supplied[^]

http://stackoverflow.com/questions/14640094/stored-procedure-or-function-expects-parameter-which-was-not-supplied[^]

http://stackoverflow.com/questions/26674149/c-sharp-stored-procedure-or-function-expects-parameter-which-is-not-supplied[^]


如果有用,请将答案标记为解决方案...
if it is helpful then please mark answer as solution...


这篇关于为什么我们必须在select方法中传递id?附加信息:过程或函数'sp_neetha'需要参数'@id',这是未提供的。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆