You must Sign In to post a response.
  • Category: ASP.NET

    How to pass value to createdby in asp.net using vb.net

    Hi how to pass parameter for created by the created user name should display but cannot display anyname can anyone help me how to fix this issue.

    cn.Open()
    Dim cmd As SqlCommand = New SqlCommand("UpdateRegistration", cn)
    cmd.CommandType = CommandType.StoredProcedure
    cmd.Parameters.AddWithValue("@Title", txtTitle.Text)
    cmd.Parameters.AddWithValue("@CounterParty", lblCounterParty.Text)
    cmd.Parameters.AddWithValue("@Company", ddlCompany.SelectedValue)
    cmd.Parameters.AddWithValue("@Custodian", ddlCustodian.SelectedValue)
    cmd.Parameters.AddWithValue("@CreatedOn", lblCreatedOn.Text)
    cmd.Parameters.AddWithValue("@OwnerDepartment", ddlOwnerDepartment.SelectedValue)
    cmd.Parameters.AddWithValue("@CreatedBy", getUserName(hUserID.Value, "name"))
    cmd.Parameters.AddWithValue("@Status", lblStatus.Text)
    cmd.Parameters.AddWithValue("@Remarks", txtRemarks.Text)
    cmd.Parameters.AddWithValue("@SecurityLevel", rbSecurityLevel.Text)
    cmd.Parameters.AddWithValue("@SelectedUsersAccess", hAlertTo.Value)
    cmd.Parameters.AddWithValue("@DocName", btnUpload.Text)
    cmd.ExecuteNonQuery()
    cn.Close()
  • #764023
    Hi

    When your login success take usersdetails put a session after that retrieve the session value in userdetails stored in your database.


    Sample code for session

    Session["LngName"] = TxtLoginName.Text;

    Name : Dotnet Developer-2015
    Email Id :kumaraspcode2009@gmail.com

    'Not by might nor by power, but by my Spirit,' says the LORD Almighty.

  • #764024
    Hi where to use that session in stored procedure

  • #764025
    Hi
    try this code


    cmd.Parameters.AddWithValue("@UserName", Session["USERNAME"]);

    Name : Dotnet Developer-2015
    Email Id :kumaraspcode2009@gmail.com

    'Not by might nor by power, but by my Spirit,' says the LORD Almighty.

  • #764026
    It shows the error like this "Procedure or function 'UpdateRegistration' expects parameter '@CreatedBy', which was not supplied. "

  • #764027
    Hi
    Share your code then

    This is your issue

    expects parameter '@CreatedBy', which was not supplied.

    Check this line

    cmd.Parameters.AddWithValue("@CreatedBy", getUserName(hUserID.Value, "name"))

    value going or not that is the issue

    Name : Dotnet Developer-2015
    Email Id :kumaraspcode2009@gmail.com

    'Not by might nor by power, but by my Spirit,' says the LORD Almighty.

  • #764028
    This is my stored procedure
    CREATE PROCEDURE [dbo].[UpdateRegistration](
    @Title nvarchar(500)
    ,@CounterParty nvarchar(200)
    ,@Company nvarchar(10)
    ,@Custodian varchar(25)
    ,@OwnerDepartment varchar(100)
    ,@Remarks nvarchar(1000)
    ,@Status varchar(2)
    ,@SecurityLevel varchar(2)
    ,@CreatedBy varchar(25)
    ,@CreatedOn datetime
    ,@SelectedUsersAccess nvarchar(max)
    ,@DocName nvarchar (max)
    )
    AS
    BEGIN
    -- SET NOCOUNT ON added to prevent extra result sets from
    -- interfering with SELECT statements.
    SET NOCOUNT ON;
    DECLARE @ID bigint
    UPDATE [dbo].[Registration]
    SET

    Title=@Title,
    CounterParty=@CounterParty ,
    Company=@Company,
    Custodian=@Custodian ,
    OwnerDepartment=@OwnerDepartment,
    Remarks=@Remarks,
    Status=@Status,
    SecurityLevel=@SecurityLevel ,
    CreatedBy= @CreatedBy,
    CreatedOn=getdate() ,
    DocName= @DocName
    WHERE SelectedUsersAccess = @SelectedUsersAccess;

    -- Insert statements for procedure here

    INSERT INTO dbo.Registration
    (Title
    ,Counterparty
    ,Company
    ,Custodian
    ,OwnerDepartment
    ,Remarks
    ,Status
    ,SecurityLevel
    ,CreatedBy
    ,CreatedOn
    ,SelectedUsersAccess
    ,DocName)

    VALUES
    ( @Title
    ,@Counterparty
    ,@Company
    ,@Custodian
    ,@OwnerDepartment
    ,@Remarks
    ,@Status
    ,@SecurityLevel
    ,@CreatedBy
    ,@CreatedOn
    ,@SelectedUsersAccess
    ,@DocName)

    END
    GO

  • #764029
    Hi
    check this parameter value have or not this parameter


    @CreatedBy

    Name : Dotnet Developer-2015
    Email Id :kumaraspcode2009@gmail.com

    'Not by might nor by power, but by my Spirit,' says the LORD Almighty.

  • #764032
    Hi,

    What about getusername method, I guess the problem is in that method. Kindly share the piece of code of getUserName(hUserId.Value,"name").

    --------------------------------------------------------------------------------
    Give respect to your work, Instead of trying to impress your boss.

    N@veen
    Blog : http://naveens-dotnet.blogspot.in/

  • #764036
    This is for the username
    Private Function getUserName(ByVal userID As String, ByVal filter As String) As String
    Dim userName As String = ""
    Dim conSQL As New SqlConnection(conStrDRS)
    conSQL.Open()
    Dim cmdSQL As SqlCommand = New SqlCommand("SELECT User_Name, cdms_ID, user_department, CDMSPath FROM [dbo].[UserAccess] WHERE User_Login_ID='" & userID & "'")
    cmdSQL.Connection = conSQL
    Dim adptSQL As New SqlClient.SqlDataAdapter(cmdSQL)
    Dim myDataSet As New DataSet()
    adptSQL.Fill(myDataSet)
    conSQL.Close()
    With myDataSet.Tables(0)
    For rowNumber As Integer = 0 To .Rows.Count - 1
    With .Rows(rowNumber)
    If filter = "name" Then
    userName = .Item(0).ToString
    ElseIf filter = "dept" Then
    userName = .Item(2).ToString
    ElseIf filter = "path" Then
    userName = .Item(3).ToString
    Else
    userName = .Item(1).ToString
    End If

    End With
    Next
    End With
    Return userName
    End Function

  • #764037
    Hi nagendra,

    Request you to kindly debug the above function and check the return username and let us know.

    --------------------------------------------------------------------------------
    Give respect to your work, Instead of trying to impress your boss.

    N@veen
    Blog : http://naveens-dotnet.blogspot.in/

  • #764038
    Hi Naveen when debug it doesn't show any error

  • #764043
    Hai Nagendra,
    It seems that the issue in the stored procedure which you have written. Also make sure that the code
    userName = .Item(1).ToString
    will work in else condition when there is no matching record for the current user.
    Hope it will be helpful to you.

    Regards,
    Pawan Awasthi(DNS MVM)
    +91 8123489140 (whatsApp), +60 14365 1476(Malaysia)
    pawansoftit@gmail.com

  • #764049
    Hi pawan I have updated the stored procedure can you please help me what else should be changed in stored procedure

  • #764072
    Hi,

    While debug the code whether did you seen the username?

    If not pass the same parameters to your procedure and check the result, whether procedure return the value whatever you expected or not.

    --------------------------------------------------------------------------------
    Give respect to your work, Instead of trying to impress your boss.

    N@veen
    Blog : http://naveens-dotnet.blogspot.in/

  • #764082
    yes Naveen when debug the code its going to username


Sign In to post your comments