如何自动生成ID并检查注册用户 [英] How to generate id automatically and checck registered user

查看:97
本文介绍了如何自动生成ID并检查注册用户的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我正在创建用于在线捐赠的网站.我希望当用户首次捐赠且仅
时,捐赠者ID应该自动生成 注册会员可以捐赠.我已使用此代码在捐赠表中插入数据,但我想自动生成ID.
该数据库具有登录,成员,捐赠和反馈表.
请帮助


i am creating website for online donation. I want donor id should auto generate when user will donate first time and only
registered member can donate.i have use this code to insert data in donate table but i want to generate id automatically.
the database has tables login, member,donate and feedback.
please help

Imports System.Data.SqlClient
Imports System.Data.DataSet
 
Partial Class Donate
    Inherits System.Web.UI.Page
 
    '---------------------------------------------------------------------
    Protected Sub RadioButtonList1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles RadioButtonList1.SelectedIndexChanged
    End Sub
 
    '---------------------------------------------------------------------
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    End Sub
 
    '---------------------------------------------------------------------
    Protected Sub btnSubmit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSubmit.Click
        Dim con As New SqlConnection
        Dim cmd As New SqlCommand
        con.ConnectionString = "Data Source=COMP-4\SQLEXPRESS;Initial Catalog=mesco;Integrated Security=True"
        cmd.Connection = con
        con.Open()
        cmd.CommandText = "insert into <pre lang="vb">member(name,age,password,confirmpassword,email,secquestion,secanswer)values('" & txtUserName.Text() & "','" & txtAge.Text() & "','" & txtPassword.Text() & "','" & txtConfirmPassword.Text() & "','" & txtEmail.Text() & "','" & txtSecurityQuestion.Text() & "','" & txtSecurityAnswer.Text() & "')"
        cmd.ExecuteNonQuery()
        MsgBox("You have been successfully Register", MsgBoxStyle.Information)
        If txtUserName.Text <> "" Then
            Session("name") = txtUserName.Text
        End If
        If txtPassword.Text <> "" Then
            Session("pass") = txtPassword.Text
        End If
        con.Close()
        txtUserName.Text = " "
        txtAge.Text = ""
        txtPassword.Text = ""
        txtConfirmPassword.Text = ""
        txtEmail.Text = ""
        txtSecurityQuestion.Text = ""
        txtSecurityAnswer.Text = "


"
结束子
End Class


"
End Sub
End Class

推荐答案

使用IDENTITY列作为主键来获取生成的值.同样在您的代码中,请使用绑定变量而不是文字连接,以防止sql注入,数据类型错误等.
Use IDENTITY column as a primary key to get a generated value. Also in your code, use bind variables instead of literal concatenations to be safe from sql injections, datatype errors etc.


使表中的ID列为主键,并自动递增.此时,添加记录时,数据库将自动生成并增加列中的值.
Make the ID column in the table the primary key, and auto-increment. At that point, the database will automatically generate and increment the value in the column when you add a record.


这篇关于如何自动生成ID并检查注册用户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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