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 601471
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T16:43:08+00:00 2026-05-13T16:43:08+00:00

Good Morning Stack Overflow, I’m new to asp.net and have a problem I’m trying

  • 0

Good Morning Stack Overflow,

I’m new to asp.net and have a problem I’m trying to sort out, maybe you can help?

The result im looking for is that the data goes into CANRADcontacts and CANRADcollreg which share a common ID.

I am populating the database via a web form, and can’t quite get the SQL correct, please see this example;

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        'Vars

        Dim FlightDateArriveString As String = (FlightMonthArrive.SelectedValue.ToString & "/" & FlightDayArrive.SelectedValue.ToString & "/" & "2010")
        Dim FlightDateDepartString As String = (FlightMonthDepart.SelectedValue.ToString & "/" & FlightDayDepart.SelectedValue.ToString & "/" & "2010")
        Dim FlightDateArrive As DateTime
        Dim FlightDateDepart As DateTime
        FlightDateArrive = Convert.ToDateTime(FlightDateArriveString)
        FlightDateDepart = Convert.ToDateTime(FlightDateDepartString)

        'Setup db connection 
        Dim CollID As Integer = 1
        Dim connstring As String = WebConfigurationManager.ConnectionStrings("ConnectionString").ToString()
        Dim conn As SqlConnection = New SqlConnection(connstring)

 Dim sql As String = ("INSERT INTO [CANRADcontacts]") & _
        (" ([Title], [Initials], [FirstName], [LastName], [Organisation], [Department], [Address], [Code],") & _
        (" [Telephone], [WorkTelephone], [Fax], [CellularTelephone],[Email], [ResearchFocus], [CollID], [ResearchFunders])") & _
        (" VALUES (@Title, @Initials, @FirstName, @LastName, @Organisation, @Department, @Address, @Code, ") & _
        ("@Telephone, @WorkTelephone, @Fax, @CellularTelephone, @Email, @ResearchFocus, @CollID, @ResearchFunders) ") & _
        ("[CANRADcollreg]([CollID], [FlightDateArrive], [FlightNameArrive], [FlightTimeArrive], [FlightDateDepart], [FlightNameDepart], [FlightTimeDepart], [AttendingLaunch], [Accomodation], [DietaryRequirements], [SpecificDietaryRequirement]) ") & _
        ("VALUES (@CollID, @FlightDateArrive, @FlightNameArrive, @FlightTimeArrive, @FlightDateDepart, @FlightNameDepart, @FlightTimeDepart, @AttendingLaunch, @Accomodation, @DietaryRequirements, @SpecificDietaryRequirement)")

        Dim comm As New SqlCommand(sql, conn)

        's1
        comm.Parameters.Add("@Title", SqlDbType.VarChar)
        comm.Parameters.Add("@Initials", SqlDbType.VarChar)
        comm.Parameters.Add("@FirstName", SqlDbType.VarChar)
        comm.Parameters.Add("@LastName", SqlDbType.VarChar)
        comm.Parameters.Add("@Organisation", SqlDbType.VarChar)
        comm.Parameters.Add("@Department", SqlDbType.VarChar)
        comm.Parameters.Add("@Address", SqlDbType.VarChar)
        comm.Parameters.Add("@Code", SqlDbType.VarChar)
        comm.Parameters.Add("@Telephone", SqlDbType.VarChar)
        comm.Parameters.Add("@WorkTelephone", SqlDbType.VarChar)
        comm.Parameters.Add("@Fax", SqlDbType.VarChar)
        comm.Parameters.Add("@CellularTelephone", SqlDbType.VarChar)
        comm.Parameters.Add("@Email", SqlDbType.VarChar)
        comm.Parameters.Add("@ResearchFocus", SqlDbType.VarChar)
        comm.Parameters.Add("@CollID", SqlDbType.VarChar)
        comm.Parameters.Add("@ResearchFunders", SqlDbType.VarChar)

        's2
        comm.Parameters.Add("@FlightDateArrive", SqlDbType.DateTime)
        comm.Parameters.Add("@FlightNameArrive", SqlDbType.VarChar)
        comm.Parameters.Add("@FlightTimeArrive", SqlDbType.VarChar)
        comm.Parameters.Add("@FlightDateDepart", SqlDbType.DateTime)
        comm.Parameters.Add("@FlightNameDepart", SqlDbType.VarChar)
        comm.Parameters.Add("@FlightTimeDepart", SqlDbType.VarChar)
        comm.Parameters.Add("@AttendingLaunch", SqlDbType.VarChar)
        comm.Parameters.Add("@Accomodation", SqlDbType.VarChar)
        comm.Parameters.Add("@DietaryRequirements", SqlDbType.VarChar)
        comm.Parameters.Add("@SpecificDietaryRequirement", SqlDbType.VarChar)

        'bind1
        comm.Parameters("@Title").Value = TitleDD.SelectedItem.ToString
        comm.Parameters("@Initials").Value = Initials.Text
        comm.Parameters("@FirstName").Value = FirstName.Text
        comm.Parameters("@LastName").Value = LastName.Text
        comm.Parameters("@Organisation").Value = Organisation.Text
        comm.Parameters("@Department").Value = DeptDiv.Text
        comm.Parameters("@Address").Value = PostalAddress.Text
        comm.Parameters("@Code").Value = Code.Text
        comm.Parameters("@Telephone").Value = Telephone.Text
        comm.Parameters("@WorkTelephone").Value = WorkTelephone.Text
        comm.Parameters("@Fax").Value = Fax.Text
        comm.Parameters("@CellularTelephone").Value = CellularTelephone.Text
        comm.Parameters("@Email").Value = EmailAddress.Text
        comm.Parameters("@ResearchFocus").Value = ResearchFocus.Text
        comm.Parameters("@CollID").Value = CollID
        comm.Parameters("@ResearchFunders").Value = ResearchFunders.Text

        'bind2
        comm.Parameters("@FlightDateArrive").Value = FlightDateArrive
        comm.Parameters("@FlightNameArrive").Value = FlightNameArrive.Text
        comm.Parameters("@FlightTimeArrive").Value = FlightTimeArrive.Text
        comm.Parameters("@FlightDateDepart").Value = FlightDateDepart
        comm.Parameters("@FlightNameDepart").Value = FlightNameDepart.Text
        comm.Parameters("@FlightTimeDepart").Value = FlightTimeDepart.Text
        comm.Parameters("@AttendingLaunch").Value = AttendingMarch23.SelectedValue.ToString
        comm.Parameters("@Accomodation").Value = Transport.SelectedValue.ToString
        comm.Parameters("@DietaryRequirements").Value = Dietary.SelectedValue.ToString
        comm.Parameters("@SpecificDietaryRequirement").Value = SpecificDietary.Text


        conn.Open()
        comm.ExecuteScalar()
        conn.Close()

    End Sub

Thanks in advance, any assistance greatly 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-05-13T16:43:08+00:00Added an answer on May 13, 2026 at 4:43 pm

    The problem is in your SQL statement — you need to have TWO INSERT statements, one for each table (notice the semi-colon that separates the two statements).

    Dim sql As String = ("INSERT INTO [CANRADcontacts]") & _
            (" ([Title], [Initials], [FirstName], [LastName], [Organisation], [Department], [Address], [Code],") & _
            (" [Telephone], [WorkTelephone], [Fax], [CellularTelephone],[Email], [ResearchFocus], [CollID], [ResearchFunders])") & _
            (" VALUES (@Title, @Initials, @FirstName, @LastName, @Organisation, @Department, @Address, @Code, ") & _
            ("@Telephone, @WorkTelephone, @Fax, @CellularTelephone, @Email, @ResearchFocus, @CollID, @ResearchFunders); ") & _
            ("INSERT INTO [CANRADcollreg] ([CollID], [FlightDateArrive], [FlightNameArrive], [FlightTimeArrive], [FlightDateDepart], [FlightNameDepart], [FlightTimeDepart], [AttendingLaunch], [Accomodation], [DietaryRequirements], [SpecificDietaryRequirement]) ") & _
            ("VALUES (@CollID, @FlightDateArrive, @FlightNameArrive, @FlightTimeArrive, @FlightDateDepart, @FlightNameDepart, @FlightTimeDepart, @AttendingLaunch, @Accomodation, @DietaryRequirements, @SpecificDietaryRequirement)")
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

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.