如何调用函数到标签 [英] How to call the function to a label

查看:67
本文介绍了如何调用函数到标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨.我可以知道如何在标签中调用函数吗?我使用了一个函数来将两个随机int&绾.我想将其放入标签中,以便将其存储在数据库中.我可以知道该怎么做吗?请帮忙.紧急!谢谢.

我要用于标签的功能是GetPassword.

我当前的代码是:

Hi. May I know how to call a function into the label? I used a function to join two random int & string together. And I want to put it into the label, so that I can store it in the database. May I know how to do that? Please help. Urgent! Thanks.

The function that I want to use for the label is GetPassword.

My current codes are :

Imports System.Data.SqlClient
Imports System.Activities.Statements

Partial Class forgetpassword
    Inherits System.Web.UI.Page

   Private Function RandomNumber(min As Integer, max As Integer) As Integer 
        Dim random As New Random()
        Return random.Next(min, max)
    End Function 'RandomNumber
    '/ '/ Generates a random string with the given length 
    '/ '/ Size of the string '/ If true, generate lowercase string 
    '/ Random string 
    Private Function RandomString(size As Integer, lowerCase As Boolean) As String
        Dim builder As New StringBuilder()
        Dim random As New Random()
        Dim ch As Char
        Dim i As Integer
        For i = 0 To size - 1
            ch = Convert.ToChar(Convert.ToInt32((26 * random.NextDouble() + 65)))
            builder.Append(ch)
        Next i
        If lowerCase Then
            Return builder.ToString().ToLower()
        End If
        Return builder.ToString()
    End Function 'RandomString
    Public Function GetPassword() As String
        Dim builder As New StringBuilder()
        builder.Append(RandomString(4, True))
        builder.Append(RandomNumber(1000, 9999))
        builder.Append(RandomString(2, False))
        Return builder.ToString()
    End Function 'GetPassword


    Protected Sub Button1_Click(sender As Object, e As System.EventArgs) Handles Button1.Click

        Dim connectionString = ConfigurationManager.ConnectionStrings("ColoreConnectionString").ConnectionString
        Dim connection As SqlConnection = New SqlConnection(connectionString)
        connection.Open()
        Dim sql As String = "UPDATE Member SET password = @password WHERE (email = email)"

        Dim Command As SqlCommand = New SqlCommand(sql, connection)

        Command.Parameters.AddWithValue("@email", tbEmail.Text)
        Command.Parameters.AddWithValue("@password", lblPw.Text)


        Command.ExecuteNonQuery()
        connection.Close()
        MsgBox("Check your email to view your password!")
    End Sub
End Class

推荐答案

我不确定您为什么要将它存储在标签中-因为您要告诉用户检查您的电子邮件以查看密码!"

但是,我不确定为什么这样做会给您带来麻烦:
I''m not sure why you want to store it in the label - given that you are telling the user to "Check your email to view your password!"

But then, I''m not sure why it is giving you a problem to do either:
lblPw.Text = GetPassword()



请注意,您需要更改SQL命令:



Do note that you need to change your SQL command:

Dim sql As String = "UPDATE Member SET password = @password WHERE (email = email)"

成为:

Dim sql As String = "UPDATE Member SET password = @password WHERE (email = @email)"

您在SQL中输入的名称和在参数中输入的名称必须相同!

The name you give in the SQL and the name you give in the parameters must be the same!


这篇关于如何调用函数到标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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