Note that there are some explanatory texts on larger screens.

plurals
  1. POGet Data from One Table and Insert to Another Via Form Submission
    primarykey
    data
    text
    <p>How do I get a UserID from one database table (Users) to be <strong>inserted</strong> into another table (Ticket)? Both columns in each table has the same datatype (int). Please take a look:<br /></p> <p><strong>Users</strong><br /> UserID<br /> UserName<br /> Password<br /> FirstName<br /> LastName<br /> Email<br /> Updated<br /> Deleted<br /></p> <p><strong>Ticket</strong><br /> TicketID<br /> DateCreated<br /> <code>UserIDNum</code> FK<br /> FullName<br /> Email<br /> Subject<br /> Message<br /> Deleted<br /></p> <p>These are all of the codes involved:<br /></p> <pre><code> Partial Public Class mysupport Inherits System.Web.UI.Page Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load If Page.IsPostBack Then MaintainScrollPositionOnPostBack = True SetFocus(helpTopicDDL) Else SetFocus(fullNameTXTBOX) End If Dim sConnection As New SqlConnection(ConfigurationManager.ConnectionStrings("TrackTicketsConnectionString2").ConnectionString) sConnection.Open() If Session("Ticket") Is Nothing Then Response.Redirect("SignIn.aspx") Else Dim cmdS As String = "Select * from Users Where Deleted='N' AND Username=@Username" Dim cmdCheckEmail As New SqlCommand(cmdS, sConnection) Dim cmd As New Data.SqlClient.SqlParameter("@Username", Data.SqlDbType.VarChar) cmdCheckEmail.Parameters.Add("@Username", SqlDbType.VarChar) cmdCheckEmail.Parameters.Item("@Username").Value = Session("Ticket") Dim obj As Object = cmdCheckEmail.ExecuteScalar() If obj IsNot Nothing Then mailLBL.Text = Convert.ToString(obj) End If End If sConnection.Close() End Sub Protected Sub submitBTN_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles submitBTN.Click Dim sdConnection As String = ConfigurationManager.AppSettings("TrackTicketsConnectionString2") Dim iRowCount As Integer Dim cmdInsertTicket As New Data.SqlClient.SqlCommand Dim conticket As New Data.SqlClient.SqlConnection conticket.ConnectionString = sdConnection cmdInsertTicket.Connection = conticket cmdInsertTicket.CommandText = "Insert Into Ticket " _ &amp; "( DateCreated, FullName, Email, TicketType, Subject, Message, Deleted)" _ &amp; "Values( @DateCreated, @FullName, @Email, @TicketType, @Subject, @Message, @Deleted)" 'Dim appUserName As New Data.SqlClient.SqlParameter("@UserName", Data.SqlDbType.NVarChar) 'cmdInsertTicket.Parameters.Add(appUserName) 'cmdInsertTicket.Parameters.Item("@UserName").Value = User.Identity.Name Dim appDateCreated As New Data.SqlClient.SqlParameter("@DateCreated", Data.SqlDbType.DateTime) cmdInsertTicket.Parameters.Add(appDateCreated) cmdInsertTicket.Parameters.Item("@DateCreated").Value = Now() Dim appFullName As New Data.SqlClient.SqlParameter("@FullName", Data.SqlDbType.VarChar) cmdInsertTicket.Parameters.Add(appFullName) cmdInsertTicket.Parameters.Item("@FullName").Value = fullNameTXTBOX.Text Dim appEmail As New Data.SqlClient.SqlParameter("@Email", Data.SqlDbType.VarChar) cmdInsertTicket.Parameters.Add(appEmail) cmdInsertTicket.Parameters.Item("@Email").Value = emailAddTXTBOX.Text Dim appTicketType As New Data.SqlClient.SqlParameter("@TicketType", Data.SqlDbType.VarChar) cmdInsertTicket.Parameters.Add(appTicketType) cmdInsertTicket.Parameters.Item("@TicketType").Value = helpTopicDDL.SelectedValue Dim appSubject As New Data.SqlClient.SqlParameter("@Subject", Data.SqlDbType.VarChar) cmdInsertTicket.Parameters.Add(appSubject) cmdInsertTicket.Parameters.Item("@Subject").Value = subjectTXTBOX.Text Dim appMessage As New Data.SqlClient.SqlParameter("@Message", Data.SqlDbType.VarChar) cmdInsertTicket.Parameters.Add(appMessage) cmdInsertTicket.Parameters.Item("@Message").Value = messageTXTBOX.Text Dim appDeleted As New Data.SqlClient.SqlParameter("@Deleted", Data.SqlDbType.Char) cmdInsertTicket.Parameters.Add(appDeleted) cmdInsertTicket.Parameters.Item("@Deleted").Value = "N" conticket.Open() Try iRowCount = cmdInsertTicket.ExecuteScalar() statusLBL.Text = "Ticket has been submitted successfully." Catch statusLBL.Text = "Ticket has not been submitted. Please try again." End Try conticket.Close() End Sub </code></pre> <p>What I really wanted is for a person's UserID to be stored in <strong>Ticket</strong> table after he has logged in to fill out a form and submitted it. I'm at a loss in how to pull the data from Users table to insert into Ticket table. Any help is much appreciated as I'm still learning.</p>
    singulars
    1. This table or related slice is empty.
    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