Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Imports System.Data.OleDb
- Public Class CreateUser1
- Inherits System.Web.UI.Page
- Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
- Dim cs As String = ConfigurationManager.ConnectionStrings("Access 2010").ConnectionString
- Dim cn As New OleDbConnection(cs)
- Dim da As New OleDbDataAdapter("SELECT * FROM Users", cn)
- Dim dt As New DataTable
- da.Fill(dt)
- da.Dispose()
- 'cn.Dispose()
- Me.grdUsers.DataSource = dt
- Me.grdUsers.DataBind()
- 'Populate ddRoles
- da = New OleDbDataAdapter("SELECT * FROM Profiles", cn)
- dt.Clear()
- da.Fill(dt)
- da.Dispose()
- cn.Dispose()
- Me.ddRoles.DataSource = dt
- Me.ddRoles.DataValueField = "ID"
- Me.ddRoles.DataTextField = "Nome"
- Me.ddRoles.DataBind()
- End Sub
- Protected Sub btnRegister_Click(sender As Object, e As EventArgs) Handles btnRegister.Click
- Dim cs As String = ConfigurationManager.ConnectionStrings("Access 2010").ConnectionString
- Dim cn As New OleDbConnection(cs)
- Dim cmd As New OleDbCommand
- With cmd
- .CommandText = "INSERT INTO Users (nome, Profile_ID) VALUES ('" & Me.txtNome.Text & "', " & Me.ddRoles.SelectedValue & ")"
- .Connection = cn
- .Connection.Open()
- .ExecuteNonQuery()
- .Connection.Close()
- .Dispose()
- End With
- cn.Dispose()
- Response.Redirect(Request.Url.AbsoluteUri)
- End Sub
- End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement