English 中文(简体)
添加储存程序并不建立数据库记录
原标题:Insert Stored Procedure does not Create Database Record

我有以下储存程序:

ALTER PROCEDURE Pro_members_Insert
@id int outPut,
@LoginName  nvarchar(50),
@Password   nvarchar(15),
@FirstName  nvarchar(100),
@LastName   nvarchar(100),
@signupDate smalldatetime,
@Company    nvarchar(100),
@Phone  nvarchar(50),
@Email  nvarchar(150),
@Address    nvarchar(255),
@PostalCode nvarchar(10),
@State_Province nvarchar(100),
@City   nvarchar(50),
@countryCode    nvarchar(4),
@active bit,
@activationCode nvarchar(50)
AS 

declare @usName as  varchar(50)
set @usName=  
select @usName=isnull(LoginName,  ) from members where LoginName=@LoginName

if @usName <>   
begin
    set @ID=-3

    RAISERROR( User Already exist. , 16, 1)
     return 
end

set @usName=  
select @usName=isnull(email,  ) from members where Email=@Email

if @usName <>   
begin
    set @ID=-4

    RAISERROR( Email Already exist. , 16, 1)
     return 
end


declare @MemID as int
select @memID=isnull(max(ID),0)+1 from members

INSERT INTO members (
id,
LoginName,
Password,
FirstName,
LastName,
signupDate,
Company,
Phone,
Email,
Address,
PostalCode,
State_Province,
City,
countryCode,
active,activationCode)
VALUES (
@Memid,
@LoginName,
@Password,
@FirstName,
@LastName,
@signupDate,
@Company,
@Phone,
@Email,
@Address,
@PostalCode,
@State_Province,
@City,
@countryCode,
@active,@activationCode)

if @@error <> 0 
set @ID=-1
else
set @id=@memID

请注意,我已“继承”这一提纲和数据库。

我正试图在我签字时插入一个新的记录。 MyDataSource如下:

 <asp:SqlDataSource runat="server" ID="dsAddMember" 
    ConnectionString="rmsdbuser"
    InsertCommandType="StoredProcedure" InsertCommand="Pro_members_Insert" 
    ProviderName="System.Data.SqlClient">
   <InsertParameters>
     <asp:ControlParameter ControlID="txtLoginName" Type="String" />
     <asp:ControlParameter ControlID="txtPassword" Type="String" />
     <asp:ControlParameter ControlID="txtEmail" Type="String" />
     <asp:ControlParameter ControlID="txtCompany" Type="String" />
     <asp:ControlParameter ControlID="txtFirstName" Type="String" />
     <asp:ControlParameter ControlID="txtLastName" Type="String" />
     <asp:ControlParameter ControlID="txtAddress" Type="String" />
     <asp:ControlParameter ControlID="txtCity" Type="String" />
     <asp:ControlParameter ControlID="ddlState" type="String" />
     <asp:ControlParameter ControlID="ddlcountryCode" Type="String" />
     <asp:ControlParameter ControlID="txtPostalCode" Type="String" />
     <asp:ControlParameter ControlID="txtPhoneNumber" Type="String" />
   </InsertParameters>
 </asp:SqlDataSource>

点击手套 除此以外:

Protected Sub btnSave_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnSave.Click
    Try
        dsAddMember.DataBind()
    Catch ex As Exception

    End Try
End Sub

当我管理这一页时,标注.aspx提供所需领域和点击提交,该页只是重载,数据库表没有反映新列入的记录。

问题:

  1. How do I catch the error messages that might be returned from the sproc?
  2. Please advise how to change signup.aspx so that the insert occurs.

Thanks, Sid

最佳回答

你们永远不会要求任何实际插入新一行的方法! 电话.Data Bind()将只将数据来源的现有数据输入“有约束的”数据元件(如文本箱和电网和 st)。

这些文字箱在你签字时如何。 • 与数据来源相关的px?

你们需要:

  • read out the values the user entered
  • actually call the stored procedure in question (directly or via SqlDataSource)
  • then maybe re-bind the form to show the new data
问题回答

您正在吞.数据库在<代码>btnSave_Click/code>上提出的所有例外。 页: 1 除例外情况外(如原样),守则意味着取消例外(如你已经指出的那样)。

至于改变你的代码,以插入——首先说明例外是什么,这将告诉你错误是什么,并可能告诉你(如果你指示的话)如何纠正错误。

问题:

1. 导言 我如何追捕可能从雕塑中退回的错误信息?

问题,即认为你可以测试数据库中的标语。 页: 1

2. 结 论 请就如何改变签名提出建议。 页: 1

如果你保证你创建的假体是正确的,那么你就可以查找如何从互联网上传呼该方的信息。





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Transaction handling with TransactionScope

I am implementing Transaction using TransactionScope with the help this MSDN article http://msdn.microsoft.com/en-us/library/system.transactions.transactionscope.aspx I just want to confirm that is ...

System.Web.Mvc.Controller Initialize

i have the following base controller... public class BaseController : Controller { protected override void Initialize(System.Web.Routing.RequestContext requestContext) { if (...

Microsoft.Contracts namespace

For what it is necessary Microsoft.Contracts namespace in asp.net? I mean, in what cases I could write using Microsoft.Contracts;?

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签