Update, edit, insert i asp.net til Access database
Jeg har oprettet en webform, hvor der er valideringer på, og samtidig vises der et udtræk af alle poster under webformen..Nu ønsker jeg at give muglighed for at opdatere posterne, indsætte nye, redigere eksisterende via webformen.
Efterlyser komplet løsning, her er min kode fra VS, flere points for hurtig komplet løsning der virker.:
----
Imports System.Data.OleDb
Public Class WebForm1
Inherits System.Web.UI.Page
#Region " Web Form Designer Generated Code "
'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.OleDbConnection1 = New System.Data.OleDb.OleDbConnection
Me.OleDbCommand1 = New System.Data.OleDb.OleDbCommand
'
'OleDbConnection1
'
Me.OleDbConnection1.ConnectionString = "Jet OLEDB:Global Partial Bulk Ops=2;Jet OLEDB:Registry Path=;Jet OLEDB:Database L" & _
"ocking Mode=1;Data Source=""C:\Inetpub\wwwroot\opgaver\opgave4\Adressekartotek.md" & _
"b"";Mode=Share Deny None;Jet OLEDB:Engine Type=5;Provider=""Microsoft.Jet.OLEDB.4." & _
"0"";Jet OLEDB:System database=;Jet OLEDB:SFP=False;persist security info=False;Ex" & _
"tended Properties=;Jet OLEDB:Compact Without Replica Repair=False;Jet OLEDB:Encr" & _
"ypt Database=False;Jet OLEDB:Create System Database=False;Jet OLEDB:Don't Copy L" & _
"ocale on Compact=False;User ID=Admin;Jet OLEDB:Global Bulk Transactions=1"
'
'OleDbCommand1
'
Me.OleDbCommand1.CommandText = "SELECT Person.Fornavn, Person.Efternavn, Person.Adresse, Person.Postnr, Postnr.By" & _
"navn, Person.Telefon FROM (Person INNER JOIN Postnr ON Person.Postnr = Postnr.Po" & _
"stnr)"
Me.OleDbCommand1.Connection = Me.OleDbConnection1
End Sub
Protected WithEvents Fornavn As System.Web.UI.WebControls.TextBox
Protected WithEvents Efternavn As System.Web.UI.WebControls.TextBox
Protected WithEvents Adresse As System.Web.UI.WebControls.TextBox
Protected WithEvents Postnummer As System.Web.UI.WebControls.TextBox
Protected WithEvents By As System.Web.UI.WebControls.TextBox
Protected WithEvents Telefonnummer As System.Web.UI.WebControls.TextBox
Protected WithEvents Fornavn_label As System.Web.UI.WebControls.Label
Protected WithEvents Efternavn_label As System.Web.UI.WebControls.Label
Protected WithEvents Adresse_label As System.Web.UI.WebControls.Label
Protected WithEvents Postnummer_label As System.Web.UI.WebControls.Label
Protected WithEvents By_label As System.Web.UI.WebControls.Label
Protected WithEvents Telefon_label As System.Web.UI.WebControls.Label
Protected WithEvents RequiredFieldValidator1 As System.Web.UI.WebControls.RequiredFieldValidator
Protected WithEvents RequiredFieldValidator2 As System.Web.UI.WebControls.RequiredFieldValidator
Protected WithEvents RequiredFieldValidator3 As System.Web.UI.WebControls.RequiredFieldValidator
Protected WithEvents RegularExpressionValidator1 As System.Web.UI.WebControls.RegularExpressionValidator
Protected WithEvents RegularExpressionValidator2 As System.Web.UI.WebControls.RegularExpressionValidator
Protected WithEvents RegularExpressionValidator3 As System.Web.UI.WebControls.RegularExpressionValidator
Protected WithEvents RegularExpressionValidator4 As System.Web.UI.WebControls.RegularExpressionValidator
Protected WithEvents RegularExpressionValidator6 As System.Web.UI.WebControls.RegularExpressionValidator
Protected WithEvents RegularExpressionValidator5 As System.Web.UI.WebControls.RegularExpressionValidator
Protected WithEvents OleDbConnection1 As System.Data.OleDb.OleDbConnection
Protected WithEvents OleDbCommand1 As System.Data.OleDb.OleDbCommand
Protected WithEvents DataGrid1 As System.Web.UI.WebControls.DataGrid
'NOTE: The following placeholder declaration is required by the Web Form Designer.
'Do not delete or move it.
Private designerPlaceholderDeclaration As System.Object
Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeComponent()
End Sub
#End Region
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
OleDbConnection1.Open()
DataGrid1.DataSource = OleDbCommand1.ExecuteReader()
DataGrid1.DataBind()
End Sub
Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Fornavn.TextChanged
End Sub
Private Sub OleDbConnection1_InfoMessage(ByVal sender As System.Object, ByVal e As System.Data.OleDb.OleDbInfoMessageEventArgs)
End Sub
End Class
--