.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
david stephan
Gaurav Pal
Post New Web Links

ListView Not Inserting Records

Posted By:      Posted Date: September 20, 2010    Points: 0   Category :ASP.Net

Hi all,

Here's the next instalment of my asp.net data access nightmare!

I've got a listview on my page, and when I run the page it correctly displays the data that it should.  However, when I add data into the empty new record and hit the 'Insert' button the page posts back but the record isn't inserted.  Annoyingly, I don't get any error!

The listview's datasource has an INSERT command and insert parameters specified.  The button seems to be triggering the listview's insert method because the ItemInserting event fires.

With no error message to go on I'm struggling to figure out what the problem is.  I have a feeling it's something to do with the makeup of the page.  The listview in question is nested within an Accordion control and the listview's data source isn't set until runtime, when it's done in the ItemDataBound event of the Accordion control.  As I say, though, it does RETRIEVE data correctly, it's just the inserting that's a problem.

I created a new, blank page with just this listview on it using the same code but not nesting it within any other control and hardcoding the datasource instead of setting it at runtime and that works perfectly, so I'm confident that my INSERT command, insert parameters and so forth are correct.

I've tried

View Complete Post

More Related Resource Links

Inserting multiple records under the single query

Hi All,       I have to insert a multiple records under the single table.So i have to execute the command in the frontend for every records. Inorder to avoid i write the query like this   insert into table1(field1,field2) values('1','Test1'),('2','Test2'); and also i tried insert into table1(field1,field2) SELECT "1","Test1" Union all SELECT "2","Test2" But I am getting syntax error. How to insert a multiple records under the single query???...

Inserting Records Based on Checkbox Selection in a Gridview

Using checkboxes, can the row of record(s) be inserted into a database? I am populating a Gridview. Done. A checkbox field has been added, when the user selects one or more rows, a submit button (which is not working) needs to inserting those records into a table. The insert statment will work outside of the page but is not working using the scenario I jut described. Is this task as I have outlined doable? txs Ayomide

Problem Facing While Inserting records into table which os dynamicaly created

Hi,I have created table into database dynamicaly,while inserting records into that dynamic table i faced problem.The name "STD000001" is not permitted in this context. Valid expressions are constants, constant expressions, and (in some contexts) variables. Column names are not permitted. this error occured.I created dynamic table by ,declare @STUDENT_Table varchar(50)set @STUDENT_Table = [dbo].[GetStudentTable](@SchoolID)declare @cmd varchar(5000)Set @cmd = 'Create Table  ' + @STUDENT_Table + '(   [student_id] [varchar](10)NOT NULL,    [school_id] [varchar](50)NULL,    [class1] [varchar](50)NULL,    [division1] [varchar](50)NULL,    [educalis_id] [varchar](16)NULL,    [roll_no] [varchar](10)NULL,    [first_name] [varchar](50)NULL,    [middle_name] [varchar](50)NULL,    [last_name] [varchar](50)NULL,    [gender] [varchar](6)NULL,    [father_name] [varchar](50)NULL,    [mother_name] [varchar](50)NULL,    [father_office_address] [varchar](200)NULL,    [mother_office_address] [varchar](200)NULL,    [home_address] [varchar](200)NULL,    [father_mobile_no] [varchar](10)NULL,    [mother_mobile_no] [varchar](10)NU

Listview Not Displaying any records


Today is the firstday that I stated to develop a complete application in WPF using Visual Studio 2010/Vb.Net

I am trying to show the records in the lisview from SQL database. However, I am not able to show the records in the Listview and I am not able to figure it out why this problem happening

This is my code

 Dim ConncectionString As String = "Data Source=SRV-TEST;Initial Catalog=AppEL;Integrated Security=True"

  Dim myConnection As SqlConnection

  myConnection = New SqlConnection(ConncectionString)



  Ticket", myConnection)

  Dim myDataTable As New DataTable

  Dim myAdapter As New SqlDataAdapter(myCommand)


  ListView1.DataContext = myDataTable.DefaultView

This is my XMAL for ListView

 <ListView Height="102" HorizontalAlig

why two records are inserting in database using Entity Framework??



i am using entity framework to access the database to insert/fetch data from database.

consider i am having two tables "AssetCheckList" and "TaskRecheckDetails"

AssetChecklist  Table






ParentAssetChecklistiID - Forigen Key of AssetCheckListID

RecheckAssetChecklistID -  Forigen Key of AssetCheckListID


when inserting the data in TaskRecheckDetails table two records are inserted with same details.

why and how to resolve it.


please help.




problem with inserting records??


When i am inserting my data i am getting this error 

An explicit value for the identity column in table 'emp' can only be specified when a column list is used and IDENTITY_INSERT is ON.

i have set Identitty specification and is identity of the table as yes so i am getting this problem whenevr i set it to no i am not getting any error,can anyone explain me why i am getting this error??

Listview: Inserting is not supported by data source 'SqlDataSource2' unless InsertCommand is speci



Does anyone know why I would get this error when adding '<%# %>' around my sqlDataSource's InsertCommand?

The SelectCommand works just fine with the '<%# %>'.

When I remove the above from the InsertCommand, it works fine, but I need it to fetch a value from parent Listview.

                    InsertCommand='<%# "INSERT INTO [Project_Detail] ([Project_Master_Key]) VALUES (2)" %>'>

 <asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:VmedIntranetConnectionString %>"
                    SelectCommand='<%# "SELECT * FROM [Project_Detail] Where Project_Master_Key = " + Eval("Project_Master_Key").ToString() %>'
                    InsertCommand='<%# "INSERT INTO [Project_Detail] ([Project_Master_Key]) VALUES (2)" %>'>

Here is my full code, maybe it makes more sense. It is two nested ListViews, the second one has the InsertCommand. It receives the parent Key, and suppose to create

Insert on button event is inserting 2 records at a time


I have a form that is doing a simple insert, then a sub insert of a certain drop down selection is made. What i dont get is why the main insert is inserting duplicates and the sub works fine inserting 1 record per text as expected. I click the button 1 time, and when i check the table, there are 2 new records.. As you can see the insert is not wrapped with any conditions, once that is inserted i check if a slection was made and runs the sub insert.

My full code can be found in this post(http://forums.asp.net/t/1608619.aspx), but here is what i have for my button event.

    protected void btnSaveServConfig_Click(object sender, EventArgs e)   
        dac.insertServerConfigintosql(txtEmailLogin, txtEmailPass, Convert.ToInt32(ddlNumEmail.SelectedValue));   
            if (Convert.ToInt32(ddlNumEmail.SelectedValue) > 0)   
                 Dictionary<string, string> camValues = new Dictionary<string, string>();   
                    foreach (HtmlTableRow row in table1.Rows)   
                        foreach (HtmlTableCell cell in row.Cells)   
                            foreach (Control control in cell.Controls)   

Inserting/updating DB looping Excel data of huge number of records




    I have requirement to read the excel data and based on some conditions ih ave either insert/ update the data in to Oracle tables. to check the condition I have to loop through the 4 columns for 4 conditions which may consist of huge number of records, where performance issue arise here. please put me in the right way or suggest me a best approach to break through the performance issue as well.

ofcourse i am writing in a service.

why is SPROC inserting two records instead of one?


Why am I getting two records inserted into the table, when I'm expecting and needing one?  The VB code below is checking whether the HTTP is secure or not, and if it is then execute the SPROC.  But for whatever reason, I'm getting two records inserted about 5 seconds apart.  Does anyone know why and how to fix?  I just need one record.  thanks


SPROC =======================================================================

ALTER PROCEDURE InsertVisitorData 
	-- Add the parameters for the stored procedure here
	@IPAddress varchar(40),  --IPv4 or IPv6
	@Browser varchar (150)	
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.

    -- Insert statements for procedure here
	INSERT INTO Visitors (ip, browser, time)
		VALUES (@IPAddress, @Browser, GetDate())

VB ==========================================================================

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If HttpContext.Current.Request.IsSecureConnection.Equals(True) Then

            Dim ipAddress As String = Request.ServerVariables("REMOTE_ADDR")
            Dim browser As String
            Dim BCaps As HttpBrowserCapabilities

Error inserting new records


Hi i am trying to insert new records by using a stored procedure with the following code:

Dim Connection
Dim Command
Dim Records
Dim Count
Dim CurrentService

Set Connection = Server.CreateObject("ADODB.Connection")
Connection.Open Application("conn")

Set Command = Server.CreateObject("ADODB.Command")
Set Command.ActiveConnection = Connection
Command.CommandType = adCmdStoredProc 'Call the stored procedure here

Select Case Request("Action")
	Case "Create"		
        Command.CommandText = "spTaxiBookingCreate" 'Call the type of stored procedure here
		Command.Parameters.Append Command.CreateParameter("@theDate", adDate, adParamInput) 'Append Parameters
		Command.Parameters.Append Command.CreateParameter("@theTime", adDate, adParamInput)
		Command.Parameters.Append Command.CreateParameter("@Location", adVarWChar, adParamInput, 50)
        Command.Parameters.Append Command.CreateParameter("@DropOff", adVarWChar, adParamInput, 50)
		Command.Parameters.Append Command.CreateParameter("@Paid", adInteger, adParamInput)
        Command.Parameters.Append Command.CreateParameter("@Notes", adVarWChar, adParamInput, 3600)
		Command.Parameters("@theDate") = Request("theDate")

Inserting records into entity framework


I must be overlooking something simple here.  I have a listview control with an entitydatasource as it's data source.  The Listview is used to insert, delete, edit and view the records.  So far so good.

I want to be able to filter the records that are returned, and I'd like to do this in the code behind.  So instead of setting the listview.datasourceID to the entitydatasource in the .aspx page, I want to bypass the entitydatasource altogether and set the listview.datasource in the code behind.  But now I have a problem inserting and editing, and I'm assuming deleting.  Appartently I now have to write the code in the ListView1_ItemInserting, ListView1_ItemUpdating and I'm assuming the ListView1_ItemDeleting events.  Is this expected behavior? 

Here's what I'm doing in the code behind:

Dim context As New WAPEntities
Dim tags = From t In context.MetaTags
                Where t.page.StartsWith(prefix)
                Order By t.page
                Select t
ListView1.DataSource = tags


Inserting new row in GridView in ASP.NET 2.0

The GridView was not designed to insert new rows, but there is a way to accomplish this with very little code. This article shows how to do that. The GridView was not designed to insert new rows, but there is a way to accomplish this with very little code.

Using ASP.NET 3.5's ListView and DataPager Controls: Displaying Data with the ListView

Prior to ASP.NET 3.5, developers who needed to display a set of records could choose between the GridView, DataList, and Repeater controls. The GridView provides rich data features, but has a very boxy layout; the DataList and Repeater allow for a more flexible layout, but lack the "point and click" data features found in the GridView, DetailsView, and FormView controls. The ListView bridges the gap between layout flexibility and built-in data features.

This article, the first in a series of articles on the ListView and DataPager controls, looks at the ListView's many available templates and illustrates how to display data. Read on to learn more!

ASP.NET GridView - edit records using JQuery Dialog

There are many ways in which you could modify modular data in Grid View:
1. Inline by making rows editable when u click on Edit
2. By using separate pages for Edit
3. By using popups/dialogs for adding/editing

WPF Tutorial - Using The ListView, Part 1

Many of the controls in WPF have a downright dizzying array of capabilities and features, due in large part to the composibility of all the components. The ListView control is a great example of this - the possibilities are almost endless. This series of tutorials on the ListView will hopefully make the space of possible options seem not quite as daunting

Inserting personal error message in ValidationSummary



I am creating a web form that requires a lot of validation. I use many of the validation control in asp.net already like RequiredFieldValidator and CompareValidator. 

My Problem: after my custom validation for the value entered return an error message, and I pressed enter key when the field is empty, my custom error message is overlapped by my ValidationSummary. 

Setting my custom error to visible = false on button click also does not seem to work as it requires for me to enter the value first.

This made me think, is there a way to insert my custom validation inside the ValidationSummary as an error message like for other validation control?

Thanks in advance

ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend