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

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

How to: Deal with UniqueIdentifiers, casting it to Guid in DAL

Posted By:      Posted Date: September 04, 2010    Points: 0   Category :ASP.Net
HelloMy users table has a column which is a unique identifier (basically this has FK relationship with aspnet_users table, of membership) Now I have an AppUser class which maps to my users tableuserid        intuser_aspnet_id  guid In my DAL, I am retreiving a user from the db an want to populate my appUser obj. How do i Convert value retreived to GuidappUsr.UserID = Convert.ToInt32(reader["user_id"]);appUsr.AspNetUserID =  reader["aspnet_user_id"];(There is no convert.ToGuid)How can this be done?appUsr.UserID = Convert.ToInt32(reader["user_id"]);                 appUsr.AspNetUserID = (Guid)reader["aspnet_user_id"];

View Complete Post

More Related Resource Links

Error: Encountered multiple versions of the same assembly with GUID...try pre-importing...TlbImp


Hi!  Can someone tell me how I can troubleshoot the following error: "Encountered multiple versions of the same assembly with GUID...try pre-importing one of these assemblies".

The website developed in VS 2010 (.Net 3.5). This error is only received on my workstation.  Another person developing the site does not experience this issue at all.  Also, not sure if this matters, but on my workstation the 'Assembly Information...' dialog contains no values even though the 'AssemblyInfo.vb' file does specify values for the title, desc, etc.  The GUID being referenced in the error is the main project of the three projects within the solution.

I tried looking through the GAC, but do not see any references to the projects or DLLs in the VS solution and am not sure what else/where to look.

If I delete the copy of the solution on my local machine and pull down a copy from source control (AnkhSVN) the solution will build with no error.  Once I make any changes, such as adding a new aspx file, then the error is received.

I can provide any additional information needed.

Want to create Page URL rewrite based on Users GUID and Display name?



I am using the asp.net membership. 

On my site I have a Profile.aspx page.

In the code behind of this page,  i get the logged in UserId (Guid) and pass

this to a method in my DAL. GetUserByUserId()


In my database I have a Table called Member which the method gets the data from

and displays details on the page about  the user.


What I want to happen is when they have logged in and are diverted to Profile.aspx,

the page URL shows www.MyWebSite/Profile/UsersName 

for example



is this possible. In my Member table I have FirstName and LastName columns or do I get the

name from the membership table.


even better would be they go straight to www.MyWebsite/JohnSmith.aspx


thank you for any help






Failed to convert parameter value from a String to a Guid.


I am trying to get the UserRole from the logged in user and send it to the database table my code is:

SqlParameter FamilyFriendsOther = new SqlParameter("@Role", SqlDbType.UniqueIdentifier);
        string [] roles = System.Web.Security.Roles.GetRolesForUser();
        if (roles.Length > 0)
            FamilyFriendsOther.Value = roles[0];

How to deal with NULL values in a SQL table


 Hi all

In order to add/update/delete data from a table I build 2 classes: 1 class containing all the table fields and another class with methods to add/insert/update/delete records. I am learning how to avoid errors when your table must use SQL NULL values. One error is when I call my UPDATE method (see below):

  public void UpdateItem(OcItemConstraintDetails item)
  SqlConnection con = new SqlConnection(connectionString);
  SqlCommand cmd = new SqlCommand("ItemConstraints_Update", con);
  cmd.CommandType = CommandType.StoredProcedure;

  cmd.Parameters.Add(new SqlParameter("@itemConstraintId", SqlDbType.Int, 4));
  cmd.Parameters["@itemConstraintId"].Value = item.ItemConstraintId;

  cmd.Parameters.Add(new SqlParameter("@path", SqlDbType.NVarChar, 150));
  cmd.Parameters["@path"].Value = item.Path;

if you watch the SQL profiler trace you will see that I am passing a value of 'default' ;so that causes me problems.

exec ItemConstraints_Update @itemConstraintId=1,@path=default

With that said, what are the best practices when your SQL table accepts NULL values and when:
- you are passing an empty value to your stored procedure;

Gridview, guid ID, and Location


Presently I have a gridview, I'm in the process of populating the gridview. One colunm "Location" is displayed as the guid ID.  I need for that colunm to be displayed as the location. Here some of the code to display the grid.

myObject orgs = new myObject();
grid.DataSource = orgs;


orgs gets a list of organizations (locations) for the grid. How can I replace the guid ID with it location. Yes the guid ID and location are in a table.

return GUID

Hi,I am using LINQ.I have 2 methods.Method 1public Guid getUserIDByProfileCode(string pCode) { var user = from p in dc.OtherProfiles where p.ProfileCode == pCode select p.UserId; return user.FirstOrDefault(); }Method 2 public Guid getStudentUserId(int id) { var stdID = from p in dc.StudentProfiles where p.ID == id select p.UserId; return stdID.FirstOrDefault(); }The first method is ok. But the second method says "Can not implicitly convert System.GUID? to System.GUID. An explicit conversion exists (Are you missing a cast?)"What is the difference between these 2 mehtods?? how can I solve it?Error 2 Cannot implicitly convert type 'System.Guid?' to 'System.Guid'. An explicit conversion exists (are you missing a cast?) C:\WebDevelopment\DrivingSchool\DrivingSchool\BLL\RegistrationBLL.cs 150 20 DrivingSchool

How best to deal with a static C Library which is currently 32-bit?

My application is a mix of a number of different executables and DLL's that are both managed and unmanaged code.  One thing everything has in common is the licensing library which is written in C as a static library.  The managed code is gaining access to this static C library via a C++ CLI assembly which links in the library.  I would like to start offering the managed code as a 64-bit app, but I don't know exactly how to overcome the issue with the static C library and the C++ CLI assembly that consumes it...Assuming I port the static C library over so that there is also a 64-bit version, is there any way I can keep the C++ CLI code bit agnostic and link in both the 32-bit and 64-bit, allowing the Windows loader to use the correct one based on the machine it is running on?  If not, how does one go about telling the C++ CLI code to use the 32-bit library when compiling the C++ CLI to target a 32-bit process and 64-bit library when targetting a 64-bit process?Sam

Querystring format to deal with Ampersand(&)

Hi, I use the following string format to navigate between webpages: String.Format(Eval("Hyper") + "?BUSINESSSTREAM={0}&Dealer={1}&LeadID={2}&Companyid={3}&SalesPerson={4}",  Eval("BusinessStream"), Eval("Dealer"),Eval("leadId"),Eval("CompanyID"),Eval("SalesPerson")) However the companyid is a text string and the company may have an "&" in it which I know will truncate the string. I have seen that this can be overcome by using  "UrlEncode" (http://forums.asp.net/p/1206489/2113465.aspx#2113465) However I cant solve the syntax. Any suggestions appeciated. Regards Colin    

Problem casting date

I'm developing a Windows Forms app using VS 2008 with a SQL Server 2005 database. I've got search form where users can search for data by entering one or two criteria. One of these is a date which corresponds to a date field in my database. The user clicks on a button, which feeds the criteria into a stored procedure. The results are displayed in a datagridview control. While the functionality works well with the non-date criteria, whenever a date criteria is used on it's own a cast error is raised ('Conversion failed when converting datetime from character string.') I've tried lots of ways of casting the date (formatting using left, right and mid finctions, using the substring function etc) but still can't get it to work. Code and SQL are shown below. Does someone know where I've gone wrong? 'DateAssayRequested' is the date in question. <vb> 'set up and initialise connection conn = New SqlConnection(etc) comm = New SqlCommand comm.Connection = conn comm.CommandText = "SPSearch" comm.CommandType = CommandType.StoredProcedure 'create input parameters, set types and values param = comm.CreateParameter param.ParameterName = "@assayid" param.Direction = ParameterDirection.Input param.Value = txtLabNo.Text

ComboBox with Name and Guid

I have a simple question.  I am trying to store a Name and a Guid inside a combobox but it only lets me store one string value.  Is there any way to store the guid value along with the Name?  I need the guid because sometimes the name will be the same.  If not what would be the best way to approach this?   Thanks,

What is the deal with ASP.NET Visual C# and Visual Basic

Hey everyone,This is my first post here, and it looks like a great community, with lots of generous help available!I am just delving into ASP.NET and the .NET framework and it appears to be a little daunting at first.What is the deal with having to choose a language for ASP.NET?Isn't ASP.NET already a web server language itself?Can you also choose JavaScript like you could in Classic-ASP?Isn't C# more for offline development anyway?I'm just trying to get a feel here, because this concept appears to be rather new to me! Any help is greatly appreciated!Thanks!!

Problem with Parameters.AddWithValue and GUID

Hi,have a problem, when i want to update a line in my database with the SQLCommand. I have following code: SqlCommand tmp_sqlcmd = new SqlCommand("UPDATE LogSend SET LogSend = @State WHERE DEVICE_UID = @Device_ID", Default_Con); tmp_sqlcmd.Parameters.AddWithValue("@State", logsend.state); tmp_sqlcmd.Parameters.AddWithValue("@Device_ID", logsend.Device_ID); int test = tmp_sqlcmd.ExecuteNonQuery(); tmp_sqlcmd.ExecuteNonQuery();But nothing happens when the command is executed. Any ideas?When i manually edit the line with:UPDATE LogSend SET LogSend = 1 WHERE DEVICE_UID = '5d8f3da0-e7c9-4a99-bb3f-246ce63ceebb'It works.Any ideas for me?Sincerely,Steven

IEnumerable Type Casting

Hello Everyone,  The following line is giving me an InvalidCastException when trying to convert to IEnumerable type, even though I have implemented IEnumerable interface.  Return New CountryInfo(CountryCodes(i), CountryNames(i)) (also in bold below)Imports System Imports Gaia.WebWidgets.HtmlFormatting Imports System.Collections.Generic Imports System.Globalization Public Class CountryInfo Implements IEnumerable Property Name As String Property Code As String Public Sub New(ByVal code As String, ByVal name As String) _Code = code _Name = name End Sub Public Function GetEnumerator() As IEnumerator Implements IEnumerable.GetEnumerator Return CType(Me, IEnumerator) End Function Public Class SearchResult Private ReadOnly _countries As List(Of CountryInfo) Private ReadOnly _query As String Friend Sub New(ByVal countries As List(Of CountryInfo), ByVal query As String) _countries = countries _query = query End Sub Public ReadOnly Property IsEmpty As Boolean Get Return _countries.Count = 0 End Get End Property Public ReadOnly Property Countries As List(Of CountryInfo) Get Return _countries End Get End Property Public Function Bui

Casting issues when using WHERE and uniqueidentifier

Hello all, I am getting the same error when trying to build the queries below by using 2 diffferent methods: DECLARE @stepIds varchar(8000), @instance uniqueidentifier, @instance_binary binary(16) SET @stepIds = '' SET @instance = '28B2D4FB-67F6-40CA-84A2-839BF3CC4B91' SET @instance_binary = CAST(@instance AS binary(16)) SELECT @stepIds = @stepIds + ',''' + stepID + '''' from Uds.RealtimeLogging WHERE instanceID = @instance_binary --Conversion failed when converting the varchar value ''' to data type int. --OR DECLARE @stepIds varchar(8000), @instance uniqueidentifier SET @stepIds = '' SET @instance = '28B2D4FB-67F6-40CA-84A2-839BF3CC4B91' SELECT @stepIds = @stepIds + ',''' + stepID + '''' from Uds.RealtimeLogging WHERE instanceID = convert(uniqueidentifier, @instance) --Conversion failed when converting the varchar value ''' to data type int. Thank you  JCD

Guid issue

Hi,I have aproblem with my guid validation - something extremely obvious and easy to work round, but just wondered why this brings up a syntax error.Guid Validator public static bool IsGuid(string candidate, out Guid value) { Regex guid = new Regex(@"^(\{){0,1}[0-9a-fA-F]{8}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{12}(\}){0,1}$"); bool isValid = false; value = Guid.Empty; if (candidate != null) { if (guid.IsMatch(candidate)) { value = new Guid(candidate); isValid = true; } } return isValid; } Code calling validator Guid identity; bool identityGuid = utRe.IsGuid(arrArg[2], identity);The synrax error gices me the standard "The best overloaded method..."arrArg[2] is a string btw.??? - anyone shed some light?

Bitmap casting

Hi, I'm working on a project that manipulate images. I put a Open Dialog Box to load images to the program. After the user choose an especific image my program does something like this: pictureBox1.Image = (Bitmap)image; It works fine with all image format I've tested. Will it work for all image formats? Thanks.

Guid. Can be auto generated?

Hello, I have the following table: CREATE TABLE [dbo].[Profiles] ( Id INT IDENTITY (1, 1) NOT NULL, Curriculum VARBINARY (MAX) FILESTREAM NULL, [Key] UNIQUEIDENTIFIER ROWGUIDCOL NOT NULL UNIQUE ) FILESTREAM_ON STORAGE The column KEY must exist because I am using a FileStream. So I need to have this column to be unique, correct? But is it possible to be auto generated instead of the need to create the value in my C# code? I mean, in this case I don't have any need to define its value in my C# code. Thank You, Miguel
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