如何让我的存储过程在我的 Visual Studio 项目中工作?

Posted

技术标签:

【中文标题】如何让我的存储过程在我的 Visual Studio 项目中工作?【英文标题】:How do I get my stored procedure to work inside my Visual Studio project? 【发布时间】:2021-11-21 04:44:50 【问题描述】:

我正在使用 Visual Studio 2017 (Windows 10),并使用 C# 制作了一个 ASP.NET 空 Web 应用程序。

在 SQL Server Express 中,我为我的网格视图编写了一个用于编辑、更新和删除的存储过程。之前我已经为编辑、更新和删除操作添加了字符串。

但出于安全原因,我现在想要一个存储过程来管理我的数据。当我在 SSMS 中执行存储过程时,它可以正常工作,到目前为止我所做的只是将存储过程实现到我的代码中。但是当我执行代码时,无法进行任何更改。

所以问题是我应该如何在 C# 中的 Visual Studio 中修改我的代码,以便在我执行我的项目时让存储过程工作?

Default.aspx

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="TestUsers.Default" %>
<link href="TestUsers.css" rel="stylesheet" type="text/css" />
<!DOCTYPE html>
  <link rel="stylesheet" href="TestUsers.css">
<link rel="shortcut icon" type="image/x-icon" href="~/orbitone.ico" />


<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>ESDTESTERS</title>
<%--    <meta http-equiv="refresh" content="20">--%>
</head>
<body>
    <form id="form1" runat="server">
        <div class="divC">
            
                <asp:GridView ID="gvTestUsers" runat="server" AutoGenerateColumns="False" ShowFooter="True" DataKeyNames="tbl_users_key" ShowHeaderWhenEmpty="True" OnRowCommand="gvTestUsers_RowCommand" OnRowEditing="gvTestUsers_RowEditing" OnRowCancelingEdit="gvTestUsers_RowCancelingEdit" 
                OnRowDeleting="gvTestUsers_RowDeleting" OnRowUpdating="gvTestUsers_RowUpdating" HorizontalAlign="Center"
                
                BackColor="#CCCCCC" BorderColor="#000000" BorderStyle="Solid" BorderWidth="3px" CellPadding="5" OnSelectedIndexChanged="GridView1_SelectedIndexChanged" Width="1470px" CellSpacing="2" ForeColor="Black">

                 <%--Theme Properties--%>
                <FooterStyle BackColor="#CCCCCC" />
                <HeaderStyle BackColor="Black" Font-Bold="True" Font-Size="Large" ForeColor="White" />
                <PagerStyle BackColor="#CCCCCC" ForeColor="Black" HorizontalAlign="Left" />
                <RowStyle BackColor="White" />
                <SelectedRowStyle BackColor="#000099" Font-Bold="True" ForeColor="White" />
                <SortedAscendingCellStyle BackColor="#F1F1F1" />
                <SortedAscendingHeaderStyle BackColor="#808080" />
                <SortedDescendingCellStyle BackColor="#CAC9C9" />
                <SortedDescendingHeaderStyle BackColor="#383838" />

                <Columns>
             <asp:TemplateField HeaderText="tbl_users_key">
                 <ItemTemplate>
                     <asp:Label Text='<%# Eval("tbl_users_key") %>' runat="server" />
                 </ItemTemplate>
<%--                 <EditItemTemplate>
                     <asp:TextBox ID="txtID" Text='<%# Eval("ID") %>' runat="server" />
                 </EditItemTemplate>--%>

             </asp:TemplateField>

              <asp:TemplateField HeaderText="Name">
                 <ItemTemplate>
                     <asp:Label Text='<%# Eval("Name") %>' runat="server" />
                 </ItemTemplate>
                 <EditItemTemplate>
                     <asp:TextBox ID="txtName" Text='<%# Eval("Name") %>' runat="server" />
                 </EditItemTemplate>
                 <FooterTemplate>
                     <asp:TextBox ID="txtNamefooter" runat="server" />
                 </FooterTemplate>
             </asp:TemplateField>

             <asp:TemplateField HeaderText="CostCenter">
                 <ItemTemplate>
                     <asp:Label Text='<%# Eval("CostCenter") %>' runat="server" />
                 </ItemTemplate>
                 <EditItemTemplate>
                     <asp:TextBox ID="txtCostCenter" Text='<%# Eval("CostCenter") %>' runat="server" />
                 </EditItemTemplate>
                 <FooterTemplate>
                     <asp:TextBox ID="txtCostCenterfooter" runat="server" />
                 </FooterTemplate>
             </asp:TemplateField>

              <asp:TemplateField HeaderText="Employee">
                 <ItemTemplate>
                     <asp:Label Text='<%# Eval("Employee") %>' runat="server" />
                 </ItemTemplate>
                 <EditItemTemplate>
                     <asp:TextBox ID="txtEmployee" Text='<%# Eval("Employee") %>' runat="server" />
                 </EditItemTemplate>
                 <FooterTemplate>
                     <asp:TextBox ID="txtEmployeefooter" runat="server" />
                 </FooterTemplate>
             </asp:TemplateField>

                    
              <asp:TemplateField HeaderText="FootPlate">
                 <ItemTemplate>
                     <asp:Label Text='<%# Eval("FootPlate") %>' runat="server" />
                 </ItemTemplate>
                 <EditItemTemplate>
                     <asp:TextBox ID="txtFootPlate" Text='<%# Eval("FootPlate") %>' runat="server" />
                 </EditItemTemplate>
                 <FooterTemplate>
                     <asp:TextBox ID="txtFootPlatefooter" runat="server" />
                 </FooterTemplate>
             </asp:TemplateField>

                    <asp:TemplateField HeaderText="WirstCord">
                 <ItemTemplate>
                     <asp:Label Text='<%# Eval("WirstCord") %>' runat="server" />
                 </ItemTemplate>
                 <EditItemTemplate>
                     <asp:TextBox ID="txtWirstCord" Text='<%# Eval("WirstCord") %>' runat="server" />
                 </EditItemTemplate>
                 <FooterTemplate>
                     <asp:TextBox ID="txtWirstCordfooter" runat="server" />
                 </FooterTemplate>
             </asp:TemplateField>

                    <asp:TemplateField HeaderText="Excluded">
                 <ItemTemplate>
                     <asp:Label Text='<%# Eval("Excluded") %>' runat="server" />
                 </ItemTemplate>
                 <EditItemTemplate>
                     <asp:TextBox ID="txtExcluded" Text='<%# Eval("Excluded") %>' runat="server" />
                 </EditItemTemplate>
                 <FooterTemplate>
                     <asp:TextBox ID="txtExcludedfooter" runat="server" />
                 </FooterTemplate>
             </asp:TemplateField>

                    <asp:TemplateField HeaderText="Comment">
                 <ItemTemplate>
                     <asp:Label Text='<%# Eval("Comment") %>' runat="server" />
                 </ItemTemplate>
                 <EditItemTemplate>
                     <asp:TextBox ID="txtComment" Text='<%# Eval("Comment") %>' runat="server" />
                 </EditItemTemplate>
                 <FooterTemplate>
                     <asp:TextBox ID="txtCommentfooter" runat="server" />
                 </FooterTemplate>
             </asp:TemplateField>

                    <asp:TemplateField>
                        <ItemTemplate>
                            <asp:ImageButton ImageUrl="~/GridImages/edit.png" runat="server" CommandName="Edit" ToolTip="Edit" Width="20px" Height="20px" /> 
                            <asp:ImageButton ImageUrl="~/GridImages/delete.png" runat="server" CommandName="Delete" ToolTip="Delete" Width="20px" Height="20px" />
                        </ItemTemplate>
                        <EditItemTemplate>
                            <asp:ImageButton ImageUrl="~/GridImages/save.png" runat="server" CommandName="Update" ToolTip="Update" Width="20px" Height="20px" /> 
                            <asp:ImageButton ImageUrl="~/GridImages/cancel.png" runat="server" CommandName="Cancel" ToolTip="Cancel" Width="20px" Height="20px" />
                        </EditItemTemplate>
                        <FooterTemplate>
                            <asp:ImageButton ImageUrl="~/GridImages/add.png" runat="server" CommandName="AddNew" ToolTip="Add New" Width="20px" Height="20px" />
                        </FooterTemplate>
                    </asp:TemplateField>
                </Columns>
            </asp:GridView>
            <br />

            <div style="margin-left: auto; margin-right: auto; text-align: center;">
            <asp:Label ID="lblSuccessMessage" Text="" runat="server" ForeColor="Green" style="text-align:center" Font-Bold="true" Font-Size="x-Large" />
            <br />
            <asp:Label ID="lblErrorMessage" Text="" runat="server" ForeColor="Red" style="text-align:center" Font-Bold="true" Font-Size="x-Large" />
            </div>

            

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

Default.aspx.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;
using System.Configuration;

namespace TestUsers

    public partial class Default : System.Web.UI.Page
    
        string connectionString = ConfigurationManager.ConnectionStrings["ConString"].ConnectionString;
        //string connectionString = "Server=KNANTE800;Database=dataterm;Trusted_Connection=True";

        protected void Page_Load(object sender, EventArgs e)
        
            if(!IsPostBack)
            
                PopulateGridView();
            
        

        void PopulateGridView()
        
            DataTable dtbl = new DataTable();
            string connectionString = ConfigurationManager.ConnectionStrings["ConString"].ConnectionString;

            using (SqlConnection sqlCon = new SqlConnection(connectionString))
            
                sqlCon.Open();
                SqlDataAdapter sqlDa = new SqlDataAdapter("Select * FROM TBL_USERS", sqlCon);
                sqlDa.Fill(dtbl);
            

            if (dtbl.Rows.Count > 0)
            
                gvTestUsers.DataSource = dtbl;
                gvTestUsers.DataBind();
            
            else
            
                dtbl.Rows.Add(dtbl.NewRow());
                gvTestUsers.DataSource = dtbl;
                gvTestUsers.DataBind();
                gvTestUsers.Rows[0].Cells.Clear();
                gvTestUsers.Rows[0].Cells.Add(new TableCell());
                gvTestUsers.Rows[0].Cells[0].ColumnSpan = dtbl.Columns.Count;
                gvTestUsers.Rows[0].Cells[0].Text = "No Data Found.";
                gvTestUsers.Rows[0].Cells[0].HorizontalAlign = HorizontalAlign.Center;
            
        

        protected void gvTestUsers_RowCommand(object sender, GridViewCommandEventArgs e)
        
            try
            
                if (e.CommandName.Equals("AddNew"))
                
                    string connectionString = ConfigurationManager.ConnectionStrings["ConString"].ConnectionString;

                    using (SqlConnection sqlCon = new SqlConnection(connectionString))
                    
                        sqlCon.Open();
                        //string query = "INSERT INTO TBL_USERS (Name,CostCenter,Employee,FootPlate,WirstCord,Excluded,Comment) VALUES (@Name,@CostCenter,@Employee,@FootPlate,@WirstCord,@Excluded,@Comment)";
                        SqlCommand sqlCmd = new SqlCommand("spEditTBL_USERS", sqlCon);
                        sqlCmd.CommandType = System.Data.CommandType.StoredProcedure;
                        // sqlCmd.Parameters.AddWithValue("@tbl_users_key", (gvTestUsers.FooterRow.FindControl("txtIDfooter") as TextBox).Text.Trim());
                        sqlCmd.Parameters.AddWithValue("@Name", (gvTestUsers.FooterRow.FindControl("txtNamefooter") as TextBox).Text.Trim());
                        sqlCmd.Parameters.AddWithValue("@CostCenter", (gvTestUsers.FooterRow.FindControl("txtCostCenterfooter") as TextBox).Text.Trim());
                        sqlCmd.Parameters.AddWithValue("@Employee", (gvTestUsers.FooterRow.FindControl("txtEmployeefooter") as TextBox).Text.Trim());
                        sqlCmd.Parameters.AddWithValue("@FootPlate", (gvTestUsers.FooterRow.FindControl("txtFootPlatefooter") as TextBox).Text.Trim());
                        sqlCmd.Parameters.AddWithValue("@WirstCord", (gvTestUsers.FooterRow.FindControl("txtWirstCordfooter") as TextBox).Text.Trim());
                        sqlCmd.Parameters.AddWithValue("@Excluded", (gvTestUsers.FooterRow.FindControl("txtExcludedfooter") as TextBox).Text.Trim());
                        sqlCmd.Parameters.AddWithValue("@Comment", (gvTestUsers.FooterRow.FindControl("txtCommentfooter") as TextBox).Text.Trim());
                        sqlCmd.ExecuteNonQuery();
                        PopulateGridView();
                        lblSuccessMessage.Text = "New Changes Complete.";
                        lblErrorMessage.Text = "";
                    
                
            
            catch (Exception ex)
            
                lblSuccessMessage.Text = "";
                lblErrorMessage.Text = ex.Message;
            
        

        protected void gvTestUsers_RowEditing(object sender, GridViewEditEventArgs e)
        
            gvTestUsers.EditIndex = e.NewEditIndex;
            PopulateGridView();
        

        protected void gvTestUsers_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
        
            gvTestUsers.EditIndex = -1;
            PopulateGridView();
        

        protected void gvTestUsers_RowDeleting(object sender, GridViewDeleteEventArgs e)
        
            try
            
                string connectionString = ConfigurationManager.ConnectionStrings["ConString"].ConnectionString;

                using (SqlConnection sqlCon = new SqlConnection(connectionString))
                
                    sqlCon.Open();
                    //string query = "DELETE FROM TBL_USERS WHERE tbl_users_key = @id";

                    SqlCommand sqlCmd = new SqlCommand("spEditTBL_USERS", sqlCon);
                    sqlCmd.CommandType = System.Data.CommandType.StoredProcedure;
                    sqlCmd.Parameters.AddWithValue("@id", Convert.ToInt32(gvTestUsers.DataKeys[e.RowIndex].Value.ToString()));
                    sqlCmd.ExecuteNonQuery();
                    PopulateGridView();
                    lblSuccessMessage.Text = "Selected Record Deleted.";
                    lblErrorMessage.Text = "";
                
            
            catch (Exception ex)
            
                lblSuccessMessage.Text = "";
                lblErrorMessage.Text = ex.Message;
            
        

        protected void gvTestUsers_RowUpdating(object sender, GridViewUpdateEventArgs e)
        
            try
            
                string connectionString = ConfigurationManager.ConnectionStrings["ConString"].ConnectionString;

                using (SqlConnection sqlCon = new SqlConnection(connectionString))
                
                    sqlCon.Open();
                    //string query = "UPDATE TBL_USERS SET Name=@Name,CostCenter=@CostCenter,Employee=@Employee,FootPlate=@FootPlate,WirstCord=@WirstCord,Excluded=@Excluded,Comment=@Comment WHERE tbl_users_key = @id";

                    SqlCommand sqlCmd = new SqlCommand("spEditTBL_USERS", sqlCon);
                    sqlCmd.CommandType = System.Data.CommandType.StoredProcedure;
                    // sqlCmd.Parameters.AddWithValue("@tbl_users_key", (gvTestUsers.FooterRow.FindControl("txtIDfooter") as TextBox).Text.Trim());//
                    sqlCmd.Parameters.AddWithValue("@Name", (gvTestUsers.Rows[e.RowIndex].FindControl("txtName") as TextBox).Text.Trim());
                    sqlCmd.Parameters.AddWithValue("@CostCenter", (gvTestUsers.Rows[e.RowIndex].FindControl("txtCostCenter") as TextBox).Text.Trim());
                    sqlCmd.Parameters.AddWithValue("@Employee", (gvTestUsers.Rows[e.RowIndex].FindControl("txtEmployee") as TextBox).Text.Trim());
                    sqlCmd.Parameters.AddWithValue("@FootPlate", (gvTestUsers.Rows[e.RowIndex].FindControl("txtFootPlate") as TextBox).Text.Trim());
                    sqlCmd.Parameters.AddWithValue("@WirstCord", (gvTestUsers.Rows[e.RowIndex].FindControl("txtWirstCord") as TextBox).Text.Trim());
                    sqlCmd.Parameters.AddWithValue("@Excluded", (gvTestUsers.Rows[e.RowIndex].FindControl("txtExcluded") as TextBox).Text.Trim());
                    sqlCmd.Parameters.AddWithValue("@Comment", (gvTestUsers.Rows[e.RowIndex].FindControl("txtComment") as TextBox).Text.Trim());
                    sqlCmd.Parameters.AddWithValue("@id", Convert.ToInt32(gvTestUsers.DataKeys[e.RowIndex].Value.ToString()));

                    sqlCmd.ExecuteNonQuery();

                    gvTestUsers.EditIndex = -1;
                    PopulateGridView();

                    lblSuccessMessage.Text = "Selected Record Updated.";
                    lblErrorMessage.Text = "";
                
            
            catch (Exception ex)
            
                lblSuccessMessage.Text = "";
                lblErrorMessage.Text = ex.Message;
            
        
    

存储过程:

-- =============================================
-- Author:      Måns Bodin
-- Create date: 2021-09.-23
-- Description: used for update ESD users
-- =============================================
ALTER PROCEDURE [dbo].[spEditTBL_USERS] 
    @ID int = null, 
    @NAME varchar(255),
    @COSTCENTER varchar(10),
    @EMPLOYEE varchar(32),
    @FOOTPLATE bit,
    @WIRSTCORD bit,
    @EXCLUDED bit,
    @MODE smallint,
    @COMMENT varchar(255),
    @MSG varchar(255) OUTPUT
AS
BEGIN
    SET NOCOUNT ON;

    DECLARE @CHECK AS int

    SET @MSG = ''

    IF @MODE = 0 
    BEGIN
        SELECT @CHECK = COUNT(1) 
        FROM TBL_USERS 
        WHERE employee = @EMPLOYEE 

        IF @CHECK != 0
        BEGIN
            SET @MSG = 'Employee already exists in database.'
            RETURN 99
        END

        INSERT INTO TBL_USERS (Name, CostCenter, Employee, FootPlate, WIRSTCORD, Excluded, Comment) 
        VALUES (@NAME, @COSTCENTER, @EMPLOYEE, @FOOTPLATE, @WIRSTCORD, @EXCLUDED, @COMMENT)

        RETURN 0
    END

    IF @MODE = 1 
    BEGIN
        UPDATE TBL_USERS 
        SET Name = @NAME, 
            CostCenter = @COSTCENTER,
            Employee = @EMPLOYEE,
            FootPlate = @FOOTPLATE,
            WIRSTCORD = @WIRSTCORD,
            Excluded = @EXCLUDED,
            Comment = @COMMENT 
        WHERE tbl_users_key = @ID
            
        RETURN 9    
    END

    IF @MODE = 2 
    BEGIN
        DELETE FROM TBL_USERS 
        WHERE tbl_users_key = @ID

        RETURN 0
    END

    --  select * from TBL_USERS 
END

【问题讨论】:

我将安装 EF Core Power Tools,并使用它将数据库逆向工程到上下文中。 EFCPT 为存储过程创建一个单独的上下文,因此您可以使用它来调用现有的过程。也许最终您会开始使用 EF 至少进行只读查询,主要是因为您必须编写以满足现代应用程序需求的每个 sproc 变体都非常乏味和乏味,或者导致次优查询/满足多个谓词的疯狂 where 子句,并从数据库中传输了太多数据.. 您在这里进行数据访问的方式非常令人麻木的样板无聊,最终您将开始寻找使其更容易的方法,编写某种调用存储过程的库......然后您将对其进行调整并弄乱它并对其进行扩展,因此它可能会返回一流的对象,然后是参数的一些动态性。然后有人会指出您浪费了几个月的生命来编写一些穷人版本的 EF;我要指出的是,您现在可以缩短它并继续编码中有趣的部分.. 【参考方案1】:

我这样修改它,它对我来说非常好用!

行更新:

    

            try
            
            //Parameters Set From Grid
                string tmpUsers_key = (gvTestUsers.Rows[e.RowIndex].FindControl("txtID") as TextBox).Text.Trim();
                string tmpName = (gvTestUsers.Rows[e.RowIndex].FindControl("txtName") as TextBox).Text.Trim();
                string tmpCostCenter = (gvTestUsers.Rows[e.RowIndex].FindControl("txtCostCenter") as TextBox).Text.Trim();
                string tmpEmployee = (gvTestUsers.Rows[e.RowIndex].FindControl("txtEmployee") as TextBox).Text.Trim();
                string tmpFootPlate = (gvTestUsers.Rows[e.RowIndex].FindControl("txtFootPlate") as TextBox).Text.Trim();
                string tmpWirstCord = (gvTestUsers.Rows[e.RowIndex].FindControl("txtWirstCord") as TextBox).Text.Trim();
                string tmpExcluded = (gvTestUsers.Rows[e.RowIndex].FindControl("txtExcluded") as TextBox).Text.Trim();
                string tmpComment = (gvTestUsers.Rows[e.RowIndex].FindControl("txtComment") as TextBox).Text.Trim();
                string tmpsMsg = "";

                //Call function for SP_UPDATE
                bool FuncResult = fcEditTBL_USERS(Convert.ToInt32(tmpUsers_key), tmpName, tmpCostCenter, tmpEmployee, Convert.ToBoolean(tmpFootPlate), Convert.ToBoolean(tmpWirstCord), Convert.ToBoolean(tmpExcluded), tmpComment,ref tmpsMsg,1);
                //Reload Page
                PopulateGridView();
                lblSuccessMessage.Text = "Selected Record Updated.";
                lblErrorMessage.Text = "";
            
            catch (Exception ex)
            
                lblSuccessMessage.Text = "";
                lblErrorMessage.Text = ex.Message;
            
    

行删除:



        try
        

            


                gvTestUsers.EditIndex = e.RowIndex;
                PopulateGridView();
               

                //Parameters for delete operation
                string dltUsers_key = (gvTestUsers.Rows[e.RowIndex].FindControl("txtID") as TextBox).Text.Trim();
                string dltName = (gvTestUsers.Rows[e.RowIndex].FindControl("txtName") as TextBox).Text.Trim();
                string dltCostCenter = (gvTestUsers.Rows[e.RowIndex].FindControl("txtCostCenter") as TextBox).Text.Trim();
                string dltEmployee = (gvTestUsers.Rows[e.RowIndex].FindControl("txtEmployee") as TextBox).Text.Trim();
                string dltFootPlate = (gvTestUsers.Rows[e.RowIndex].FindControl("txtFootPlate") as TextBox).Text.Trim();
                string dltWirstCord = (gvTestUsers.Rows[e.RowIndex].FindControl("txtWirstCord") as TextBox).Text.Trim();
                string dltExcluded = (gvTestUsers.Rows[e.RowIndex].FindControl("txtExcluded") as TextBox).Text.Trim();
                string dltComment = (gvTestUsers.Rows[e.RowIndex].FindControl("txtComment") as TextBox).Text.Trim();
                string dltsMsg = "";


                //Call function for SP_Delete
                bool FuncDelete = fcEditTBL_USERS(Convert.ToInt32(dltUsers_key), dltName, dltCostCenter, dltEmployee, Convert.ToBoolean(dltFootPlate), Convert.ToBoolean(dltWirstCord), Convert.ToBoolean(dltExcluded), dltComment,ref dltsMsg,2);

                if (FuncDelete == false)
                
                    lblErrorMessage.Text = dltsMsg;
                    lblSuccessMessage.Text = " ";
                    return;
                



                PopulateGridView();
                lblSuccessMessage.Text = "Selected Record Deleted.";
                lblErrorMessage.Text = "";


                gvTestUsers.EditIndex = -1;


            
        
        catch (Exception ex)
        
            lblSuccessMessage.Text = "";
            lblErrorMessage.Text = ex.Message;
        
    

行命令:


        try
        
            if (e.CommandName.Equals("AddNew"))
            


                int tbl_users_key = 0;

                TextBox myTxt;

                myTxt = ((TextBox)gvTestUsers.FooterRow.FindControl("txtNamefooter"));
                string Name;
                Name = myTxt.Text;

                string CostCenter;
                myTxt = ((TextBox)gvTestUsers.FooterRow.FindControl("txtCostCenterfooter"));
                CostCenter = myTxt.Text;

                string Employee;
                myTxt = ((TextBox)gvTestUsers.FooterRow.FindControl("txtEmployeefooter"));
                Employee = myTxt.Text;

                Boolean  FootPlate;
                myTxt = ((TextBox)gvTestUsers.FooterRow.FindControl("txtFootPlatefooter"));
              // string tmpFootPlate = (gvTestUsers.FooterRow.FindControl("txtFootPlate") as TextBox).Text.Trim();
               // boo Convert.ToBoolean(tmpFootPlate)
                FootPlate = Convert.ToBoolean(myTxt.Text);

                Boolean WirstCord;
                myTxt = ((TextBox)gvTestUsers.FooterRow.FindControl("txtWirstCordfooter"));
                WirstCord = Convert.ToBoolean(myTxt.Text);

                Boolean Excluded;
                myTxt = ((TextBox)gvTestUsers.FooterRow.FindControl("txtExcludedfooter"));
                Excluded = Convert.ToBoolean(myTxt.Text);

                string Comment;
                myTxt = ((TextBox)gvTestUsers.FooterRow.FindControl("txtCommentfooter"));
                Comment = myTxt.Text;


                string sMsg;

                sMsg = "";


               bool btest = fcEditTBL_USERS(tbl_users_key, Name, CostCenter, Employee, FootPlate, WirstCord, Excluded, Comment, ref sMsg,0);


                if (btest == false)
                
                    lblErrorMessage.Text = sMsg;
                    lblSuccessMessage.Text = " ";
                    return;
                

                PopulateGridView();

                lblSuccessMessage.Text = Name + " Was Added To Record.";
            
        
        catch (Exception ex)
        
            lblSuccessMessage.Text = "";
            lblErrorMessage.Text = ex.Message;
        

【讨论】:

以上是关于如何让我的存储过程在我的 Visual Studio 项目中工作?的主要内容,如果未能解决你的问题,请参考以下文章

如何让我的 Visual Studio 测试套件 Web 测试迭代我的数据源?

我应该如何让我的 Ionic / Apache Cordova / Visual Studio 环境保持最新?

我应该如何在Mercurial存储库中设置我的Visual Studio项目/解决方案?

如何让我的应用程序使用 Visual Studio 找到第三方 DLL?

压缩文件后(它们从 Visual Studio 中的文件路径引用打开),如何让我的应用程序从单独的 Winform 打开? (C#)

如何让我的 Visual Studio 在没有调试程序的情况下运行不断扩大 RAM 使用量直到 RAM 已满,甚至将 SSD 用作“RAM”?