B
bob
Hi,
I try ro insert programmatically data into 2 fields of a Access table from
a detailsview.
My problem is: when clicking on the 'insert' button, nothing happens (no
error but no data inserted).
When 'burning' the values in the sql command, it works, but when using the
inputted values in the detailsview, it doesn't.
The problem is inthe line:: field1 = e.Values("field1") which renders
nothing, i think.
Thanks for helping
Bob
Here the code:
--------------
In the aspx file:
<form id="form1" runat="server">
<aspetailsView ID="DetailsView1" runat="server" defaultmode="Insert"
AutoGenerateInsertButton="True">
</aspetailsView>
</form>
In the aspx.vb file::
Imports System.Data.OleDb
Partial Class test
Inherits System.Web.UI.Page
Friend oConnection As OleDbConnection
Friend sConnectionString As String
Friend sql As String
Friend comd As OleDbCommand
Friend dtreader As OleDbDataReader
Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Load
oConnection = New OleDbConnection()
sConnectionString = "Provider = Microsoft.Jet.OLEDB.4.0; Data Source =
c:\mydb.mdb; Jet OLEDB;"
sql = "select field1,field2 from mytable;"
oConnection.ConnectionString = sConnectionString
oConnection.Open()
comd = New OleDbCommand(sql, oConnection)
dtreader = comd.ExecuteReader
DetailsView1.DataSource = dtreader
DetailsView1.DataBind()
oConnection.Close()
End Sub
Protected Sub DetailsView1_ItemInserting(ByVal sender As Object, ByVal e
As System.Web.UI.WebControls.DetailsViewInsertEventArgs) Handles
DetailsView1.ItemInserting
oConnection.Open()
Dim field1, field2 As String
field1 = e.Values("field1")
field2 = e.Values("field2")
'sql = "insert into pc (field1,field2) values('ok','ok2')"
'this works
sql = "insert into pc (field1,field2) values('" & naam & "','" &
lokaal & "')"
comd = New OleDbCommand(sql, oConnection)
comd.ExecuteNonQuery()
dtreader.Close()
oConnection.Close()
End Sub
I try ro insert programmatically data into 2 fields of a Access table from
a detailsview.
My problem is: when clicking on the 'insert' button, nothing happens (no
error but no data inserted).
When 'burning' the values in the sql command, it works, but when using the
inputted values in the detailsview, it doesn't.
The problem is inthe line:: field1 = e.Values("field1") which renders
nothing, i think.
Thanks for helping
Bob
Here the code:
--------------
In the aspx file:
<form id="form1" runat="server">
<aspetailsView ID="DetailsView1" runat="server" defaultmode="Insert"
AutoGenerateInsertButton="True">
</aspetailsView>
</form>
In the aspx.vb file::
Imports System.Data.OleDb
Partial Class test
Inherits System.Web.UI.Page
Friend oConnection As OleDbConnection
Friend sConnectionString As String
Friend sql As String
Friend comd As OleDbCommand
Friend dtreader As OleDbDataReader
Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Load
oConnection = New OleDbConnection()
sConnectionString = "Provider = Microsoft.Jet.OLEDB.4.0; Data Source =
c:\mydb.mdb; Jet OLEDB;"
sql = "select field1,field2 from mytable;"
oConnection.ConnectionString = sConnectionString
oConnection.Open()
comd = New OleDbCommand(sql, oConnection)
dtreader = comd.ExecuteReader
DetailsView1.DataSource = dtreader
DetailsView1.DataBind()
oConnection.Close()
End Sub
Protected Sub DetailsView1_ItemInserting(ByVal sender As Object, ByVal e
As System.Web.UI.WebControls.DetailsViewInsertEventArgs) Handles
DetailsView1.ItemInserting
oConnection.Open()
Dim field1, field2 As String
field1 = e.Values("field1")
field2 = e.Values("field2")
'sql = "insert into pc (field1,field2) values('ok','ok2')"
'this works
sql = "insert into pc (field1,field2) values('" & naam & "','" &
lokaal & "')"
comd = New OleDbCommand(sql, oConnection)
comd.ExecuteNonQuery()
dtreader.Close()
oConnection.Close()
End Sub