Can't Insert A Guid (userID) Into Table!

Feb 10, 2011

I'm creating a web project for one of my uni modules using Visual studio 2010. I'm using asp.net membership and have all of my sql-server tables set up correctly (I'm pretty sure).

I have a form that I have created myself that inserts into the database using sqlDataSource.insert(). I had some problems initially with not being able to insert any data into the table at all, but I have cleared that up.

My problem now is that I need to insert the currently logged in user's userID into one of the columns of the table. But every time I hit the submit button, I am told I cannot insert null values in the userID column.

I can retrieve the userID using this snippet:

[Code]....

This is the code behind for the page:

[Code]....

As you can see it is a bit of a mess, I've been frantically trying different variations, as I need to catch up a little with other uni modules.

Here is my SQLDataSource from the .aspx page, The controlparameters work fine for the other data I am inserting. maybe the <asp:parameter name="userID" /> is wrong?

[Code]....

I'm relatively new to vb, and I come from a html & css background.

View 1 Replies


Similar Messages:

ADO.NET :: Insert Userid As System.Guid To The Uniqueidentifier Field?

Dec 12, 2010

I'm trying to insert userid that is a System.Guid into an additional table into the same userid field that is uniqueidentifier. It seems as it cannot insert the System.Guid type there wether I'm passing it directly as the System.Guid or as a String then converting.

<System.ComponentModel.DataObjectMethodAttribute _
(System.ComponentModel.DataObjectMethodType.Insert, True)> _
Public Function InsertUserInterests( _
ByVal strUserId As String, ByVal strCode As String) _
As Boolean
Dim userInter As New DS1.tblUserInterestsDataTable
Dim userInterRow As DS1.tblUserInterestsRow = userInter.NewtblUserInterestsRow
Dim ug As System.Guid = New Guid(strUserId)
userInterRow.UserId = ug ' This didn't go through I beleive
userInterRow.InterestCode = strCode
userInter.AddtblUserInterestsRow(userInterRow)
Dim rowsAffected As Integer = Adapter.Update(userInter)
Return rowsAffected = 1
End Function

View 3 Replies

C# - Insert GUID Into SQL Table?

Mar 26, 2011

I'm using ASP.Net/C# and I have a form that allows people to add information into a table and along with it I want to collect the Current Users GUID and insert it.

I have a field setup (UserID) as a unique identifier and I have the following code:

protected void Page_Load(object sender, EventArgs e)
{
MembershipUser currentUser = Membership.GetUser();
Guid temp = (Guid)(Membership.GetUser(User.Identity.Name).ProviderUserKey);
Guid @currentUserID = temp;
}
SqlConnection con = new SqlConnection("Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\ASPNETDB.MDF;Integrated Security=True;User Instance=True");
SqlCommand cmd;
protected void Button1_Click(object sender, EventArgs e)
{
con.Open();
cmd = new SqlCommand("insert into Accom (UserID) values('" + @currentUserID + "')", con);
cmd.ExecuteNonQuery();
}

I basically want to link the variable to the Database how as the above gives errors.

View 4 Replies

Security :: Best Way To Insert Newly-created UserId Into A Second Table Also?

Sep 25, 2010

[Code]....

View 9 Replies

Security :: How To Automatically Insert UserId Into A Custom Table

Jun 27, 2010

I recently read Scott Mitchell's article series "Examining ASP.NET's Membership, Roles, and Profile". In Part 6 [URL] It says "to store additional, user-specific fields...If you are using the SqlMembershipProvider, this would mean creating an additional database table that had as a primary key the UserId value from the aspnet_Users table and columns for each of the additional user properties."

I created a table named Thread to store some specific users information and comments they make. I set the ThreadId as the primary key and the UserId as the foreign key to the UserId in aspnet_Users table. But when I run the application and use a user's account to submit a comment, there is an error in my Comments.aspx.vb page "Cannot insert the value NULL into column 'UserId', table 'ASPNETDB.dbo.Thread'; column does not allow nulls. INSERT fails.The statement has been terminated."

How can I make the logged-on user's UserId inserted into the Thread table when storing the user's other data information?

View 6 Replies

Security :: Where Is The UserID Guid On Login

Feb 11, 2010

We have a system where an administrator can login and create other users. If the administrator creates another user, then logs out and immediately logs back in with the new user information the UserID Guid is not available. If you log out and login again with the new username it works, or if you simply refresh the page it works.

Why does it not work on the first run?

View 1 Replies

Getting A Username From A UserID (guid) In Web Forms?

Mar 26, 2011

So I'm almost finished my project but I'm stuck. In my application's database I save some records that contain the currently logged in user's userID - and so when it comes to displaying these records, I've been just been outputting the userID whilst developing the rest of the application. Through googling I've found this line of code that will get the a username based on a userID:

Dim membershipUser As MembershipUser = Membership.GetUser(New Guid(userGUID))

Which works great if I can supply it with a GUID - but I'm struggling to see how I can use this line of code if for example I want to show the usernames for comments on an article which are contained in a repeater control.Maybe it would be simpler to just merge my application's database with the asp.net membership database (ASPNETDB.mdf) so I can just select the username in SQL instead - but I'm not even sure how to do that.

View 1 Replies

Forms Data Controls :: How To Change Insert To Edit If UserId Exist In Table

Feb 6, 2011

It sounds pretty simple, but I can't find a way to make it work. I have a FormView with a InsertTemplate where it inserts the current logged in user's UserId and content from a HTMLeditor, and a EditTemplate where it retreives the current logged in UserId and shows content from database in the HTMLeditor.

How can I get it to show EditTemplate if the userId exist in the table, and InsertTemplate if the UserId does not exist in the table?

View 4 Replies

Databases :: Use GUID As Userid When Using MySql For Membership?

Apr 23, 2010

I have followed this tutorial which provides me with Membership, Role, Profile etc.

[URL]

Everything is working fine, but I noticed that the userid is in standard INT, not GUID. Is it possible to get around this? I want the userid as GUID.

View 4 Replies

Automapper, Auto Assign Guid To UserId Of UserDTO?

Dec 1, 2010

I want to assign Guid to UserId of my UserDTO if UserId is Null. Is it possible to do this in the CreateMap or creating any formatter?. I am using automapper as an attribute on my Actions in controller.

protected override void Configure()
{
Mapper.CreateMap<User, UserDTO>()
.ForMember(d => d.FullName, o => o.MapFrom(s => s.FirstName + " " + s.LastName));
}

View 1 Replies

C# - Adding Another Table Where UserID Can Have A Relationship With Another UserID?

Mar 31, 2011

I have a confusing question, I have a user table and it stores all the usual data for a user that you would expect but im trying to figure out how a user could add another user?

Sounds strange but each user in the User table has his own UI which is UserID how could I add another table where UserID can have a relationship with another UserID?

i.e how would I right the syntax for the above question if I wanted to display all the UserIDs friends on a page. How would I add a friend.

View 4 Replies

DataSource Controls :: Insert Row Using Guid From Querystring?

Apr 2, 2010

I have a page with a gridview that is populated depending upon the value of the querystring passed to it - there is a one-to-many relationship between Jobs and Locations respectively (one job can have many locations), and the gridview is a list of Locations that are associated with a particular Job. So far so good.

I have a DetailsView below whose DefaultMode is Insert to add a new location, though I can't seem to capture the JobId (guid) from the querystring. I've tried the following code on the Datasource's Inserting event:

[Code]....

but on both occasions I get the same error: Foreign Key constraint broken on JobId field. It seems that the querystring is not being passed to the datasource for inclusion in the insert.

View 2 Replies

SQL Server :: How To Insert GUID Type Value Into Uniqueidentifier Field Using Vb.net

Dec 14, 2010

I am workining in vb.net and sql. In DB have a uniqueidentifier field and want to insert in it,

When try to send data, some thing parameter: ByVal value as GUID

In the query : '"& Value &"' then errors occurs " Operator & not define or supporting and System.GUID "

If do like that : '"& CAST(Value as uniqueidentifier) &"' then Says CAST undefined same with Convert.

View 3 Replies

Can Insert Rows To Table A Based On Values In Table B By A Single INSERT Statement

Dec 7, 2010

I am doing a data warehouse project.I have two tables tblA (id, type) and tblB(city, no_crimes, type).I want to create (insert) a number of rows based on the value of no_crimes.For Example, in tblB(Leeds, 2000, murder). SO, I need to insert 2000 rows into tblA by a single INSERT statement (not 2000 statements).

View 3 Replies

Web Forms :: Matching Logged In Userid To ID In Another Table?

Feb 2, 2011

So I have been trying to pull the userid of whoever is currently logged in and match it to another table that it is a fk in. I have some code that should work but I get an error that says specified cast is not valid in line 10.

here is the code I have behind file:

[Code]....

View 4 Replies

C# - Retrieve UserId From Membership Users Table?

Jun 6, 2010

i'm new to membership. i have a table named contact, with a field, userId that must get its data from the membership users table. so when a user is created i have to get the userId from membership users table. how can i do that?

View 1 Replies

Security :: Pass Membership UserID To Db Table?

Oct 1, 2010

i'm using asp.net membership for logins/registeration. i have a bookings table with few fields, lets say first_name, last_name, product_name and userID.when the user submits 'buy' i want to get the userID from the membership user tablem that way i know whose made the booking. i'll have these two tables (bookings & user tables) linkedbut how do i get userID from the user table to pass to bookings table? i checked the membership class and it gives options like-Membership.GetUser(), Membership.GetUserNameByEmail(), Membership.GetAllUsers() etcothing for getting user id. user id is stored like this: c1c91682-449f-45dd-b20e-3dac5315bba4

View 2 Replies

Web Forms :: Custom Table Profile Provider Has Different UserID?

Feb 11, 2010

I created the Table Profile Provider with the VB.NET and it works perfectly but I have one issue with it.. My Table (UserProfile) can't be linked with any other tables because the UserID on userprofile is different than any other table yet when I do profile.firstname on the vb code it works perfectly. Say for example I have a username called john If I do select * from aspnet_users where username = 'john' The results would come to 2 rows, 1 which has a userid and applicationid that is used on ALL the tables in my database EXCEPT for userprofile The second one would have a applicationid and userid that is only use on my userprofile table.

View 1 Replies

VB - Adding UserId To Custom Table After Membership.CreateUser?

Nov 18, 2010

There are lots of posts about this issue but I can't work out the answers as most of them are for C# or similar. I'm trying to automatically insert the UserId generated by Membership into a custom table. I have membership working correctly, as well as the custom table (I'm able to insert other things from the registration form). But I can't get it to extract the generated UserId and insert it into the custom table. Here's my code:

[Code]....

As you can see I've experimented with the parameters for inserting the record, but that doesn't work (I get an error about ProviderKey not being a part of system.web.security.membershipuser).

View 3 Replies

Security :: Link Aspnet_users To Table With UserID As Foreign Key?

Aug 10, 2010

Perhaps this is a simpler VS9 question, but I want to link a SQLServer table with additional user data to the standard SQLServer membership table using the GUID userID as a foreign key. I go into design mode of my table, right-click on relationships, and click add in the dialog. but the left hand column shows me only the tables in my database. How do I get it to show the tables in the ASPNETDB.MDF database? I went through the tutorial (http://www.asp.net/learn/security/tutorial-08-cs.aspx), but it seems to magically appear in there without explanation.

View 3 Replies

C# - Trying To Select UserID, FirstName, SecondName, PicturePath(from Pictures Table)?

Apr 2, 2011

I'm trying to select UserID, FirstName, SecondName, PicturePath(from Pictures table) LIKE FirstName (string search = textbox.text)

OdbcCommand("SELECT UserID, FirstName, SecondName, p.PicturePath FROM User LEFT JOIN Pictures p ON p.UserID = u.UserID WHERE FirstName LIKE '%" + search + "%' ORDER BY UserID DESC", cn))

My syntax is way messed up. My table structure:

View 4 Replies

Web Forms :: Table Profile Provider Writes UserID Twice In Query - Causes Error

May 21, 2010

I get this error while trying to run my project: "Column name 'UserID' appears more than once in the result column list." Indeed, the query generated in my SqlTableProfileProvider.vb is the following (text in brackets [] has been changed):

"IF EXISTS (SELECT 1 FROM [table] WHERE UserId = @UserId) BEGIN UPDATE [table] SET UserID=@Value0, LastUpdatedDate=@LastUpdatedDate WHERE UserId = '[Guid]'END ELSE BEGIN INSERT [table] (UserId, UserID, LastUpdatedDate ) VALUES ('[Guid]', @Value0,
@LastUpdatedDate) END"

I'll emphasize that the above statement is generated in SqlTableProfileProvider.vb, which was written by .Net people. While I have little control over its source, I've apparently given the fodder whereby the mistake can be generated. Any clues as to why UserID is being written twice in the statement?

View 2 Replies

Web Forms :: Passing CurrentUser.UserId With File Upload Control To Database Table?

Feb 18, 2010

implementing an file upload control that uploads the binary data to the database table and associates it with the correct user/the current user who uploaded the data.

View 8 Replies

ADO.NET :: Insert Data Into Two Table At The Same Time - Multiple INSERT Statements?

Oct 26, 2010

I am trying to insert data into two table at the same time , but i'm successding in inserting data into only one table at a time on button click .

[Code]....

When i run the code, data gets inserted into table "implantDetails" only. Are multiple INSERT statments allowed?

View 1 Replies

DataSource Controls :: Select A Record From A Table And Insert Into B Table Using Linq?

Jun 29, 2010

how can i select a record from A table and insert into B table using linq?

View 2 Replies







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