DataSource Controls :: Inserting New Record Error?

Jan 14, 2010

I have the logged-in user's Guid stored in a session variable. My understanding is that when the Guid is passed to the session variable it becomes a string. When I use the detailsview control I have to convert the session variable back to a guid and I've been doing it like this and it seems to work fine:

e.values("UserId") = session("LoggedInUserId")
Dim UserId as Guid = New Guid()

When I try to use the Insert() command after the following:

SqlDataSource3.InsertParameters("UserId").DefaultValue = Session("LoggedInUserId")

I get an "InvalidCastException" error with the comment "Conversion from type 'Guid' to type 'String' is not valid." I'm assuming the session variable needs to be converted to a type Guid since that's what I've had to do with the Detailsview control. I've tried a few different ways of converting the session variable back to a Guid so the insert command will work, but no matter which method of conversion I try I get errors such as "value of type system.guid cannot be converted to 'string'. I'm confused because I thought I was supposed to convert it from a string to a Guid. The "UserId" parameter is a non-primary key uniqueidentifier in the database.

View 2 Replies


Similar Messages:

DataSource Controls :: Getting The PK ID Of The Newly Created Record After Inserting A New Record?

Dec 20, 2010

I am creating an album using the following stored procedure, which returns the primary key for the newly created record:

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[fpa_sp_albums_update_insert]
@album_id int,
@album_name nvarchar (50),
@album_descr nvarchar(250),
@album_img_cover_id_FK int,
@album_creation_date date
AS
If @album_id > 0
UPDATE [fpa_albums]
SET
album_name=@album_name,
album_descr= @album_descr,
album_img_cover_id_FK = @album_img_cover_id_FK,
album_creation_date = @album_creation_date
Where ((album_id = @album_id))
Else
INSERT INTO [fpa_albums] (
album_name,
album_descr,
album_img_cover_id_FK,
album_creation_date)
VALUES (
@album_name,
@album_descr,
@album_img_cover_id_FK,
@album_creation_date)
Return SCOPE_IDENTITY();

I execute the above stored procedure using the SQLHELPER. The VB.NET code for the page is as follows:

[Code]....

However, the createdAlbumID always shows -1 instead of the id for the newly created album.

View 1 Replies

DataSource Controls :: Get The Inserting ID Out Of The Record Using Scope_identity

Jun 9, 2010

Im trying to get the ID out of the record that i'm inserting using scope_identity. I've add the following line of code to the Insert statements in the sqldatasource - SET @insID = Scope_Identity() I've add the following line to the Insert parameter list

asp:Parameter
Name="insID"
Type="Int32"
Direction="Output"

I now want to insert a number records into the database using the following:

Dim insID As Object = e.Command.Parameters("@insID").Value ' gets out latest ID
Dim ordernumber As String = "CX" & insID.ToString & DateTime.Now.DayOfYear.ToString
sqlOrders.InsertParameters("orderNumber").DefaultValue = ordernumber
sqlOrders.InsertParameters("orderDate").DefaultValue = DateTime.Now
sqlOrders.InsertParameters("customerID").DefaultValue = userID
sqlOrders.InsertParameters("productID").DefaultValue = productID
sqlOrders.InsertParameters("totalPrice").DefaultValue = "0.00"
sqlOrders.InsertParameters("status").DefaultValue = "Paid"

I currently have this code in the SQLDataSource_Inserting sub but the first line only works once the record is inserted. How can i get the ID out as im inserting the parameters?

View 3 Replies

DataSource Controls :: Ado.net Dataservices Inserting A Record (with Inheritance Applied)

May 23, 2010

I have an entity model, in which I have a table per type inheritance. Is it possible to perform an insert using ado.net dataservice and asp.net ajax library? I was trying the following client code :

dataContext.insertEntity(childData, "Parent");

I was getting this response from server : Error processing request stream. Type information must be specified for types that take part in inheritance.

View 1 Replies

DataSource Controls :: Linq To Sql: How To Retrieve Identity Column Value Before For Inserting Any Record

Apr 3, 2010

I am in a serious trouble right now, i wanted to know that how to write a query in LINQ to SQL to retrieve identity column's current value before inserting any value.

I need this cos i m building a windows app n i need to display this value before inserting a record. I have tried DataContext.ExecuteCommand('DBCC CHECKIDENT (Tablename)') but it returns the number of rows modified.

View 2 Replies

DataSource Controls :: Store Procedure Is Returning -1 Even Though It Is Successfully Inserting/updating Record

Jan 29, 2010

My insert is adding a record to the database in the call to the stored procedure in SQL Server, but a -1 is returned - Shouldn't it return 0 if the insert/update was successful?

Result = myCommand.ExecuteNonQuery();

View 3 Replies

DataSource Controls :: Using NewId() To Identify Current Inserting Record And Affect All Other Records In Table?

Apr 27, 2010

I've got a sp as below:

The functionality I want to achieve is that when isHomePageFeatured is checked then this record is set to 1 for that column and for all the other records in the table it is set to 0.

This is fine for update as I can use the property Id to compare against, but for the newly inserted record it doesn't yet have a propertyId so I wondered if using newID() to affect all other records would have the same affect.

[Code].....

View 3 Replies

ADO.NET :: Cast Error When Inserting Record With Linq (to Sql)?

Aug 22, 2010

I'm getting the following error message:

Unable to cast object of type 'System.Data.Linq.DataQuery`1[Username]' to type 'Username'.

I've been searching but can't find a solution. This particular table has 4 columns. The first column is the int indentifier. Column 2 is "username" (varchar50) and is the primary key. Column3 is "userID" (uniqueidentifier) and column 4 is "active" (varchar5)

[Code]....

View 7 Replies

C# - Subsonic 3.0.0.4 ActiveRecord Template For MySQL Error On Inserting New Record?

Nov 7, 2010

public void Add(IDataProvider provider){

var key=KeyValue();
if(key==null){
var newKey=_repo.Add(this,provider);
this.SetKeyValue(newKey);
}else{
_repo.Add(this,provider); //NullReferenceException was unhandled by user code

[Code]....

View 1 Replies

DataSource Controls :: Error When Inserting With Sqldatasource Control?

Aug 5, 2010

I have a problem with inserting some records into an access database using the sqldatasource control.

Here is Ex 1:

[Code]....

Ex 2:
[Code]....

I have tried both examples above, and some variants of them, but I'm getting errors.

With Ex 1 I get:

System.Data.OleDb.OleDbException was unhandled by user code
ErrorCode=-2147217913
Message="Data Type Mismatch." [code]....

what is wrong with both examples above?I'm adding values to all fields in the table, except for the ID field, ofcouse.

View 2 Replies

DataSource Controls :: Getting Error While Inserting The Values To Parameters?

Mar 19, 2010

I'm using Enterprise library, but the idea is the same. I have a SqlStringCommand and the sql is constructed using StringBuilder in the forms of "insert into table (column1, column2, column3) values (@param1-X, @param2-X, @parm3-X)" + " ";where "X" reprents a "for loop" about 700 rows like so
[Code]....

So after all is done, I have 700 insert statements in one batch and of course, I did another 700 loops and added the values to those parameters. It runs fine and fast for a few days. However, last night, suddenly I get this error

[Code]....

View 2 Replies

DataSource Controls :: Inserting Via GridView And Sqldatasource - Null Error.

Jan 24, 2011

I am not able to figure out why I am getting the null error at SqlDataSource10.Insert(); I tried running through break points and i checked the Insert statement and it has all the required values .. but I get error saying it cannot insert null into NrNarrativeDays. I am working off a sample at this link..

http://www.aspdotnetfaq.com/Faq/How-to-insert-row-in-GridView-with-SqlDataSource.aspx

[Code]....

Datasource and Gridview code is below

[Code]....

View 6 Replies

DataSource Controls :: Insert A Record Error - Can't Perform Create, Update, Or Delete Operations On 'Table?

May 11, 2010

when i want insert a record i see an error like this Can't perform Create, Update, or Delete operations on 'Table(MainMenuLink)' because it has no primary key. with this codes:

MyLinqDataClassesDataContext db = new MyLinqDataClassesDataContext();
MainMenuLink li = new MainMenuLink { Link = "www.tprogrammer.com", LinkSubject = "subject" };
db.MainMenuLinks.InsertOnSubmit(li); [code]....

View 2 Replies

Forms Data Controls :: Clear Formview After Inserting Record?

Oct 11, 2010

When page load it is invisible. I have a button1 onclick make it visible and people can input data the press insert. I set it invisible right in Formview Insert eventhandler code.

When people click that button1 again to add 2nd record the form appear again as desired. However, the data from 1st record is still there.

What code I can make in eventhandler to make sure when button1 is clicked the Formview does not contain any data from last entry ?

The formview clear the data from 1st record if I did not set visible/invisible.

View 2 Replies

Data Controls :: Paging When Inserting Record On Nested GridView

May 4, 2014

I have a GridView1 With Paging allowed, PageSize = 10. And a Nested GridView2. The INSERT function on nested GridView2 works well until the number of record is 10.

On inserting the 11th record, the GridView1 is recorded normally in page 2 of 2. The Nested GridView2 does not fired properly. it appears empty on the 11th record (page 2 of 2), but instead add its record on the last recorded ID on page 1 of 2.

When I remove the paging, everything works well.

How to resolve the paging issue with Nested GridView on "INSERT" record?

View 1 Replies

Data Controls :: How To Stop Transaction While Inserting Record If Duplicate Value Found In DB

Nov 7, 2010

I have a formview and inside it there are two textboxes taking integer as input.I put a condition that if both textboxes are empty then user should be notified that "Please put value in any one of the textbox".It is working very fine.From database side DBA checked that if user input any integer value in any one of the two textboxes and if it is already found in database then there is no insertion.The problem is that everything is working fine and i checked in the database that the record is also not inerting due to duplicate check but user is getting message that "Record inserted successfully."How to stop this message and how to notify user that you have entered duplicate value and transaction should also not been done. Means all inputs should be there rather than clearing textboxes that could be done when "Record Inserted."
[Code]....

View 1 Replies

Forms Data Controls :: Check Duplicate While Inserting Record From Texbox?

Aug 25, 2010

On inserting record, I want to check that for example if a user enters a telephone number for any record is already in the database then it should validate that the number already exists in table and you cannot enter a duplicate value.

Then if user will provide some other telephone number then he allows to insert record.

For insertion of record I used ObjectdataSource.

User will enter telephone number in a simple textbox.

I may want to inform that I am working in asp.net2.0 and also not allowed to use any third party control or ajaxtoolkit.

View 11 Replies

DataSource Controls :: Row Count Shows 1 Record But There Is No Record In Database Table

Jun 24, 2010

I am counting from a table for that i have written code as below

protected void get_Id_Afterpoint()
{
int counter = 0;
string strSql = "select count(*) as ID from tblEnergy where ID=?";
OdbcCommand com = new OdbcCommand(strSql, con);
com.Parameters.AddWithValue("ID", DropDownList1.SelectedValue);
OdbcDataAdapter oda = new OdbcDataAdapter(com);
DataTable dt = new DataTable();
oda.Fill(dt);
if (dt.Rows.Count == 0)
{
lblID2.Text = "1";
}
else
{
counter = dt.Rows.Count;
counter = counter + 1;
lblID2.Text = Convert.ToString(counter);
}
}

there is no record related to DropDownList1.SelectedValue. but as i am counting if(dt.rows.count) and i put break point on the bolded part it shows 1 record. how it can be possible?

View 5 Replies

Forms Data Controls :: Change Gridview Page Upon Inserting / Deleting Record?

Jun 22, 2010

I am having trouble changing page numbers on my gridview after deleting a record if the deletion of the record causes there to be no more records on that page. Currently I have a form below the gridview that adds a record to the datasource of the gridview.

[Code]....

Code behind stuff:

[Code]....

Now with this code above, if I insert a new record using the form below the gridview, it will reload and go to the new page if the insertion causes the record to appear on a new page, however when I delete that record, thus causing nothing to be on that page, the gridview visually just dissappears. I've got the gridview bound by a linqdatasource control, and on the page_load function I only databind if the page is not a postback.

View 2 Replies

DataSource Controls :: Inserting Data With Object Datasource?

Aug 9, 2010

This is the first time I have been working on databases and I am trying to insert data using an object datasource but no data is being inserted and no exception is thrown. I'm not sure where I am going to wrong. I am putting user data into session variables and inserting the session variables into the dataacess class layer and have a try and exception but nothing being thrown. Any help would be really appreciated because I don't know even where to start looking with this or how I can get the error to be thrown. Please see some of my code below to give an idea of what I am doing

Object Access Class
public void InsertCarPolicyHolder(PolicyHolderClass ph, CarInsuranceOptions options)
{

[code]...

View 2 Replies

Inserting A Record Into Database?

Oct 10, 2010

[Code]....

[Code]....

[Code]....

[Code]....

[Code]....

View 2 Replies

SQL Server :: How To Prevent Inserting Record

Aug 14, 2010

Students can subscribe for any project via a webform. Table 'project ' contains all the proposed project and table 'student' contain the name of the student and the project-id.Now, suppose there is a limit of 4 students for project 'A' and there are already 3 subscribed students for that project. One more student can choose that project. The code-behind checks whether the limit is not reached (by counting the amount students for that project in table 'student') before inserting that student in the table 'student'.

My problem is that when two students fills the webform for the same project and click on the 'save-button' exactly at the same time, the code has no time to check the limit and both students are inserted into table 'student'. Is there a way to lock the table or something in order to preventing this?

[Code]....

View 5 Replies

ADO.NET :: Inserting Part Of Record To Database

Aug 4, 2010

I am using ASP.NET 2.0, C#, SQL Server 2005. I have a gridview which has 10 records. I want to only insert few records(for example: 3 records) to the database. How to insert only part of the whole data to the database.

View 3 Replies

MVC :: SQL Exception When Inserting New Record In Database

Dec 26, 2010

i got the following error when i tried to inser a recrord from my MVC web application , although the insert will work fine when i tried to inser the record manually from the databse explorer, and i checked all the FK relationship they sound valid:-

The INSERT statement conflicted with the FOREIGN KEY constraint "FK_Articles_Users". The conflict occurred in database "84A669DA0E532BEFAFBE7BE38367071F_IONALNETWORKWEBAPPLICATIONPROFESSIONALNETWORKWEBAPPLICATIONAPP_DATAPROFESSIONALNETWORKDB.MDF", table
"dbo.Users", column 'User_ID'.The statement has been terminated.

View 12 Replies

MVC :: ListView Replacement -- Inserting A Record?

Mar 16, 2010

I'm a new user of ASP.NET MVC and I'm trying to replicate the ListView control from WebForms in an AJAX-y manner. Take the following as an example:

[Code]....

The "ItemTemplate", "EditItemTemplate", and "InsertItemTemplate" replacements are implemented as Partial Views, so the view for this page looks something like this:

[Code]....

The edit/update flow is very simple. The user clicks the "edit" button, an AJAX request is made to get the "EditItemTemplate", and the contents of that row are replaced with the "EditItemTemplate". When the user clicks "Update" in the edit row, the form is submitted via AJAX and the resulting content replaces the "EditItemTemplate".

The part I'm not sure how to deal with is the InsertItemTemplate. When the user submits the insert form, I need two partial views to be returned: one to replace the InsertItemTemplate (clear the form or show any validation errors), and one to insert into the table as a new record (ItemTemplate). I'm not sure what to do about this...the only options I've come up with are:

Make 2 Ajax requests -- one to insert the item and get the ItemTemplate for the new item and another to get a clean InsertItemTemplate Make 1 Ajax request for JSON -- render the ItemTemplate and InsertItemTemplates into strings and then put them into a JSON object that can be analyzed client-side (ex: { itemtemplate: "<tr>...</tr>", insertitemtemplate: "<tr>...</tr>" }) Make 1 Ajax request for the ItemTemplate and then manually clear the InsertItemTemplate form client-side (removing any form entries and validation elements)

None of these options really seem that great to me...especially #1 (because of a second AJAX request) and #3 (because it keeps my solution from being easily reused on other "ListView replacements" due to the need to manually clear the form). #2 is somewhat acceptable but still kind of hacky because rendering partial views to strings and then sending them in JSON isn't easy to do and ends up being a bit of a hack.

View 5 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved