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

  • Home
  • SEARCH
  • 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 9217319
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T02:36:33+00:00 2026-06-18T02:36:33+00:00

I’m using ASP.NET (C#) and I have code which inserts a new row into

  • 0

I’m using ASP.NET (C#) and I have code which inserts a new row into a database. When I run it, I get the error “Input string was not in a correct format”.

I think I have narrowed this error down to the users GUID uniqueidentifier, which needs to be passed into the insert statement. (created from the asp:login)

I know I can call for this UserID by using Membership.GetUser(User.Identity.Name).ProviderUserKey.ToString()
but then I need to convert back to a Guid using new Guid(string)

This doesn’t seem to work for me. Here is my code-behind: Can you spot any errors??

public partial class LoggedIn_CreateDoc : System.Web.UI.Page
{
    SqlConnection sqlConn;
    SqlDataAdapter sqlDA;
    DataSet ds;
    String strConn = ConfigurationManager.ConnectionStrings["1722555Connection"].ConnectionString;

    protected void createDoc_Click(object sender, EventArgs e)
    {
        SqlConnection connection = new SqlConnection();

        connection.ConnectionString = ConfigurationManager.ConnectionStrings["1722555Connection"].ConnectionString;
        connection.Open();

        SqlCommand cmd = new SqlCommand();
        cmd.Connection = connection;
        cmd.CommandTimeout = 0;

        string commandText = "INSERT INTO Documents (Name, Description, RcdID, Location, AccessLevel, DateCreated, AuthorID, DocStatus, EngStatus, QaStatus, DesignStatus) VALUES(@Name, @Description, @RCD, @Location 1, @Date, @AuthorID, 1, 1, 4, 4)";
        cmd.CommandText = commandText;
        cmd.CommandType = CommandType.Text;

        cmd.Parameters.Add("@Name", SqlDbType.VarChar, 50);
        cmd.Parameters.Add("@Description", SqlDbType.VarChar, 300);
        cmd.Parameters.Add("@RCD", SqlDbType.Int);
        cmd.Parameters.Add("@Location", SqlDbType.Int);
        cmd.Parameters.Add("@Date", SqlDbType.DateTime);
        cmd.Parameters.Add("@AuthorID", SqlDbType.UniqueIdentifier);

        cmd.Parameters["@Name"].Value = TextBoxDocTitle.Text;
        cmd.Parameters["@Description"].Value = TextBoxDocDescription.Text;
        cmd.Parameters["@RCD"].Value = ListBoxSeries.DataValueField;
        cmd.Parameters["@Location"].Value = ListBoxLocation.DataValueField;
        cmd.Parameters["@Date"].Value = DateTime.Now;
        cmd.Parameters["@AuthorID"].Value = new Guid(Membership.GetUser(User.Identity.Name).ProviderUserKey.ToString());

        cmd.ExecuteNonQuery();

        connection.Close();

        Response.Write(@"<script language='javascript'>alert('Your new document has been created. \n You can now find it in your Task Panel!');</script>");

        Response.Redirect("TaskPanel.aspx");
    }
}
  • 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-18T02:36:34+00:00Added an answer on June 18, 2026 at 2:36 am

    I don’t think that the problem is your ProviderUserKey. The cast doesn’t fail – the insert does.

    Do you need to convert RCD and Location to int values? You are currently trying to pass strings to int fields.

    You should use ListBox.SelectedValue to retrieve the selected values from these fields, after which you can use Int32.TryParse to convert them to integers (or Int32.Parse if you want an exception thrown should the cast fail).

    ListBox.DataValueField is not used to retrieve the selected value from the ListBox, but to tell it what field in the bound datasource it should treat as its value and – as such – it is the name of a field, not the value within it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have a French site that I want to parse, but am running into
I would like to run a str_replace or preg_replace which looks for certain words
I have an autohotkey script which looks up a word in a bilingual dictionary
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I have an array which has BIG numbers and small numbers in it. I
I have a text area in my form which accepts all possible characters from

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.