Note that there are some explanatory texts on larger screens.

plurals
  1. POCan't seem to insert a guid (userID) into table!
    primarykey
    data
    text
    <p>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).</p> <p>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.</p> <p>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.</p> <p>I can retrieve the userID using this snippet:</p> <pre><code> Dim userID As String Dim memUser As MembershipUser memUser = Membership.GetUser() userID = memUser.ProviderUserKey.ToString() e.Command.Parameters(0).Value = userID </code></pre> <p>This is the code behind for the page:</p> <pre><code>Public Class WebForm1 Inherits System.Web.UI.Page 'Dim userID As Guid = CType(memUser.ProviderUserKey, Guid) Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load 'Dim UserID As Guid = CType(Membership.GetUser.ProviderUserKey, Guid) 'memUser = Membership.GetUser() Dim userID As Guid Dim memUser As MembershipUser memUser = Membership.GetUser() userID = memUser.ProviderUserKey If IsPostBack() Then Session.Add("UserID", userID) Else userID = Session("UserID") End If TextBox1.Text = userID.ToString End Sub Protected Sub SqlDataSource1_Selecting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.SqlDataSourceSelectingEventArgs) Handles SqlDataSource1.Selecting e.Command.Parameters(0).Value = userID End Sub Protected Sub buttonInsertCitation_Click(ByVal sender As Object, ByVal e As EventArgs) Handles buttonInsertCitation.Click SqlDataSource1.Insert() End Sub End Class </code></pre> <p>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.</p> <p>Here is my SQLDataSource from the .aspx page, The controlparameters work fine for the other data I am inserting. maybe the <code>&lt;asp:parameter name="userID" /&gt;</code> is wrong?</p> <pre><code>&lt;InsertParameters&gt; &lt;asp:parameter name="userID" /&gt; &lt;asp:ControlParameter ControlID="textNotes" Name="notes" PropertyName="Text" /&gt; &lt;asp:ControlParameter ControlID="textEssayTitle" Name="essayTitle" PropertyName="Text" /&gt; &lt;asp:ControlParameter ControlID="radioIsPrivate" Name="isPrivate" PropertyName="Text" /&gt; &lt;asp:ControlParameter ControlID="dropPaperID" Name="paperID" PropertyName="Text" /&gt; &lt;/InsertParameters&gt; </code></pre> <p>I'm relatively new to vb, and I come from a html &amp; css background.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload