Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8151853
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T15:31:41+00:00 2026-06-06T15:31:41+00:00

I am developing an ASP.Net VB Web Application The application contains a GridView which

  • 0

I am developing an ASP.Net VB Web Application

The application contains a GridView which displays the records of a user table from my created datable. The database is an Sql server database.

The code below inserts data into one table and through the built in function @@Identity to insert the most recently added record id (tt_id) from the trainingTbl table and inserting that record id into the userAssessmentTbl. Adding the identity to the second userAssessmentTbl table works fine.

Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs)
        Dim lblUsr2 As Control = FindControlRecursive(MultiTabs, "txtUsr")
        Dim strQuery As String
        Dim cmd As SqlCommand

        strQuery = "Insert into trainingTbl(s_id, t_date, EditorId, wa_id, st_id) values(@s_id , @t_date, @EditorId, @wa_id, @st_id  ) Insert into userAssessmentTbl(tt_id, UserId) values(@@Identity, @UserId)"

        cmd = New SqlCommand(strQuery)

        cmd.Parameters.AddWithValue("@s_id", DDLCourse.Text)
        cmd.Parameters.AddWithValue("@t_date", Convert.ToDateTime(txtDate.Text))
        cmd.Parameters.AddWithValue("@EditorId", User.Identity.Name.ToString())
        cmd.Parameters.AddWithValue("@st_id", myLblStation.Value().ToString)
        cmd.Parameters.AddWithValue("@wa_id", myLblWatch.Value().ToString)
        cmd.Parameters.AddWithValue("@UserId", lblUsr2.UniqueID.ToString)
        InsertUpdateData(cmd)
    End Sub

The issue I’m having seems to be centered on how I insert a uniqueidenifier from a GridView into a userAssessmentTbl database!

And how, I guess using a loop I can insert the UserId records from that Gridview (GridView1) into the userAssessmentTbl table along with the looped id from the @@Identity.

This part of the insert parameter seems to be incorrect:

cmd.Parameters.AddWithValue("@UserId", lblUsr2.UniqueID().ToString)

And the error I’m met with is: ‘Conversion failed when converting from a character string to uniqueidentifier.‘

I’ve also tried it like this:

cmd.Parameters.AddWithValue("@UserId", SqlDbType.UniqueIdentifier).Value().ToString()

And im met with the error: ‘Operand type clash: int is incompatible with uniqueidentifier’

The qusetion has slightly changed to how do I Insert a String into SQL DB Where DataType Is Uniqueidentifier?

Any help will be really appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T15:31:43+00:00Added an answer on June 6, 2026 at 3:31 pm

    Well first of all:

    @@IDENTITY returns the most recently created identity for your current
    connection, not necessarily the identity for the recently added row in
    a table. Always use SCOPE_IDENTITY() to return the identity of the
    recently added row.


    Secondly, to asnwer your question:

    The SQL type Uniqueidentifier and the CLR type Guid match up.

    So instead of passing "@UserId" in as a parameter you need to create a Guid out of the string value.

    Dim userID As Guid = New Guid(lblUsr2.UniqueID.ToString)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm developing a web application using asp.net. There is a text box which contains
I'm developing a ASP.NET Web application in which a table is converted to an
I am developing an asp.net web form application that displays some info on separate
I have a project (Web Application) which I have been developing in C#/ASP.NET, and
We are developing an asp.net 2.0 web application in that user can sign-up or
Which IoC to consider while developing ASP.NET Web application project and what are the
I'm developing ASP.net application which use web services. There are no data base connections
I'm developing an ASP.Net web application which makes use of MySQL via the MySQL-Provided
My team is developing an ASP.NET application, which among other things contains an import
I'm developing an ASP.NET web application. When a user loads a specific page on

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.