Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Datagrid Control > what' wrong with this?

Reply
Thread Tools

what' wrong with this?

 
 
bob
Guest
Posts: n/a
 
      10-16-2006
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.DetailsViewInsertEventAr gs) 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


 
Reply With Quote
 
 
 
 
Phil H
Guest
Posts: n/a
 
      10-23-2006
Hi Bob

A DetailsView object is meant to be attached to a DataSource. In your
case the most suitable type would be an AccessDataSource.

The AccessDataSource will have an InsertQuery property which you need
to configure. It is a string that comprises an SQL INSERT command
(usually) with parameters. The parameters can be set so that they are
read from the text boxes of your details view.

If you are using VS2005 then all this is made very easy using various
wizard and dialogues.

The example code you give doesn't contain any settings to indicate
where the DetailsView object gets its data from nor where it sends it.

Is that any help?

Phil Hall

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Have I bought wrong product? enquirer Wireless Networking 2 06-10-2005 10:59 PM
Zero Config keeps connecting to the wrong AP =?Utf-8?B?ZGdyaWZmaXRo?= Wireless Networking 2 03-04-2005 05:52 PM
Is XML Doc wrong or is Schema wrong? (or both) Matthew XML 7 01-07-2005 10:05 PM
wrong connection status Peter Welk Wireless Networking 0 12-22-2004 03:26 PM
XP SP2 Wrong IP on connection D Wells Wireless Networking 3 12-09-2004 03:35 AM



Advertisments