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
Similar Messages:
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
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
Sep 14, 2010
I'm just curious, why its not bigint or int ? is that because GUID is easy to generate ?
View 8 Replies
Aug 7, 2010
I have a database call that is comparing UserID column of two tables. The UserID is a uniqueidentifier. The page errors on the r.read() line with Conversion failed when converting from a character string to uniqueidentifier. I'm not sure how to code this to avoid the error.
cmd.CommandText = "SELECT a.CenterName FROM Centers a INNER JOIN UserInfo u ON a.CenterID = u.CenterID WHERE u.UserID='{ + SessionManager.UserID + }'";
r = cmd.ExecuteReader();
r.Read();
View 5 Replies
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
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
Oct 12, 2010
I am trying to match a username to a userid which are in 2 different sql tables. Here is my select statement:
SELECT aspnet_Users.UserName
FROM aspnet_Users INNER JOIN
aspnet_starterkits_Projects ON aspnet_Users.UserName = aspnet_starterkits_Projects.ProjectManagerId
When I run this i get an error message: "Conversion failed when converting from a character string to uniqueidentifier" Is there anyway around this? Or a different select statement etc?
View 8 Replies
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
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
Feb 19, 2010
I am attempting to use SqlBulkCopy to import data from an XML document. I receive the following error when executing WriteToServer: Invalid cast from 'System.String' to 'System.Guid'
View 1 Replies
Feb 14, 2010
When a user creates an account for my web application using the create user wizard additional steps have been added to take more details and store them in another table. Now this tables primary key is set to uniqueidentifier, is it possible to have that unique identifier automatically generated when the query is run to insert a new row for a new user?
View 1 Replies
Sep 17, 2010
[Code]....
System.InvalidCastException was unhandled by user code
Message=Unable to cast object of type 'System.Guid' to type 'System.String'.
Source=System.Data.Linq
System.Data.Linq.SqlClient.SqlProvider.System.Data.Linq.Provider.IProvider.Execut
View 4 Replies
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
Apr 4, 2011
How does System.Guid.NewGuid() know that the values it generates are unique, for example when i use in a loop?Does it internally store data somewhere? .
View 1 Replies
Sep 18, 2010
[Code]....
Column UserId = uniqueidentifier
Compilation Error
Description:
An error occurred during the compilation of a resource required to service
this request. Please review the following specific error details and modify your
source code appropriately. Compiler Error Message: CS0019:
Operator '==' cannot be applied to operands of type 'string' and
'System.Guid'Source Error:
[Code]....
Line 93:
Line 94: var creditcard = from c in db.tbl_Payments
Line 95: where UserID == c.UserId
Line 96: select c;
Line 97:
View 4 Replies
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
Jan 24, 2011
This error is occuring randomly, and I can't seem to pinpoint what is causing it. For the most part, the code works fine. I'm confused why it works sometimes, but then suddently craps out on me, lol.It happens in the code when I call upon the asp.net membership provider. It only seems to happen when i use Membership.GetUser() to grab the logged in user's information.
View 9 Replies
May 7, 2010
I'm using ASPNetDB.mdb database for membership login and another database to store ads that members submit.
In my webform that collects the ad info I'd like to populate a field with the logged in member's Name.
View 5 Replies
Nov 18, 2010
The detailsview is used for logged users to add a new item to a table in my sql database. The detailsview default mode is set to "insert".
The UserID is a field in the table in which the user enter the new record.
How can I get the UserID Guid value assigned automatically on pageload to the specific bound field in my detailsview
View 3 Replies
Sep 25, 2010
[Code]....
View 9 Replies
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
Jul 28, 2010
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
View 8 Replies
Jul 30, 2010
I am working on Scott Mitchell's ASP.Net in 24 hours book. I am running into what looks like a simple problem that is getting the best of me.
When a page loads, the UserId of the currently logged in user will be retrieved in the page Load event and placed into the Text value of a Label. But, when the page opens when I am running the app, I am getting an error in the lower left corner of the browser. When I open up the error message, I see this:
Webpage error details
Message: 'UserIDValue' is undefined
Line: 92
Char: 1
Code: 0
URI: http://localhost:51035/PhotoAlbum24hrs/PhotoAdmin/ManageCategories.aspx
Here is the web page's Load event (VB) code:
[Code]....
Here is line 92 and the surrounding lines from the page source when I run the app:
[Code]....
This matches what is in Scott's book. (Or else I have been looking at it too long and have missed something.)
If I make the UserId Label visible, I can see the logged in user's ID displayed on the page. So, what is going on here? Why am I getting this error?
View 6 Replies
Sep 15, 2010
I receive this error message: LINQ to Entities does not recognize the method 'System.Guid GetUserId()' method, and this method cannot be translated into a store expression. This is my code:
DB.Users user = db.Users.FirstOrDefault(u => u.Id == BOL.GetUserId());
BOL.GetUserId() returns a GUID of the current logged-in user (and this works works).
How can I make this LINQ code line work? Or, what is the shortest alternative? In the mean time I found out that there is a difference between LINQ to SQL and Entities. I use Entities because of the TailspinSpyworks example... but my code is using LINQ to SQL. My current solution is to use a var:
var userId = BOL.GetUserId();
DB.Users user = db.Users.FirstOrDefault(u => u.Id == userId);
Is this a good solution? And, is the execution time of Entities faster than SQL?
View 4 Replies