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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T01:47:50+00:00 2026-06-13T01:47:50+00:00

I’ve created 2 tables in a database, each table has a CompanyID field that’s

  • 0

I’ve created 2 tables in a database, each table has a CompanyID field that’s in relationship with eachother

In my registration page the company has to register the following info:

  1. CompanyID
  2. Company Name
  3. Business Type
  4. Contact Person
  5. Telephone
  6. Address
  7. e-mail
  8. Password

The company then logs in using their Company Name and Password, once logged in a company can post a job and the problem I have is in my jobtable there is also a field called CompanyID

How can I retrieve the CompanyID from the already registered companys stored in my Company table and use it

        SqlParameter p6 = new SqlParameter("CompanyID", 'here' );

my full code:

    protected void Button1_Click(object sender, EventArgs e)
{
    string strcon = "Data Source=.\\SQLEXPRESS;AttachDbFilename=|DataDirectory|\\VC_temps.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True";
    SqlConnection con = new SqlConnection(strcon);

    SqlCommand com = new SqlCommand("Store-Jobs", con);
    com.CommandType = CommandType.StoredProcedure;
    SqlParameter p1 = new SqlParameter("Job", TextBox1.Text);
    SqlParameter p2 = new SqlParameter("JobType", DropDownList1.Text);
    SqlParameter p3 = new SqlParameter("StartDate", TextBox3.Text);
    SqlParameter p4 = new SqlParameter("Time", TextBox2.Text);
    SqlParameter p5 = new SqlParameter("JobID", TextBox1.Text.Substring(3).ToUpper());
    SqlParameter p6 = new SqlParameter("CompanyID", );
    SqlParameter p7 = new SqlParameter("PositionFilled", "NO");
    SqlParameter p8 = new SqlParameter("Description", TextBox4.Text);
    com.Parameters.Add(p1);
    com.Parameters.Add(p2);
    com.Parameters.Add(p3);
    com.Parameters.Add(p4);
    com.Parameters.Add(p5);
    com.Parameters.Add(p6);
    com.Parameters.Add(p7);
    com.Parameters.Add(p8);
    con.Open();
    com.ExecuteNonQuery();
    Labelinfo.Text = "Post successful.";
}
  • 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-13T01:47:51+00:00Added an answer on June 13, 2026 at 1:47 am

    There are several ways to do this. Since the user is logging in to a specific company then I am assuming the CompanyId would be the same during the entire session. Therefore I would recommend retrieving the CompanyId during the login process and storing it into the Session variable. Then you get the CompanyId from this session variable anytime you wish.

    An alternative would be to pass the company name into the stored procedure and let the stored procedure get the CompanyId using the Company Name value.

    On a secondary note….I like to show best practices when I see code that could have problems. Your code will work fine if everything succeeds but if exceptions occur then you will leave SQL connections open. I have taken the liberty to refactor your code to show an alternative…

    string strcon = "Data Source=.\\SQLEXPRESS;AttachDbFilename=|DataDirectory|\\VC_temps.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True"; 
    
    // Use "using" statement to guarantee connection is closed even if exception occurs
    using (SqlConnection con = new SqlConnection(strcon))
    {
        con.Open(); 
        using (SqlCommand com = con.CreateCommand("Store-Jobs"))
        {
            com.CommandType = CommandType.StoredProcedure; 
            com.Parameters.AddWithValue("Job", TextBox1.Text); 
            com.Parameters.AddWithValue("JobType", DropDownList1.Text); 
            com.Parameters.AddWithValue("StartDate", TextBox3.Text); 
            com.Parameters.AddWithValue("Time", TextBox2.Text); 
            com.Parameters.AddWithValue("JobID", TextBox1.Text.Substring(3).ToUpper()); 
            com.Parameters.AddWithValue("CompanyID", ); 
            com.Parameters.AddWithValue("PositionFilled", "NO"); 
            com.Parameters.AddWithValue("Description", TextBox4.Text); 
            com.ExecuteNonQuery(); 
        }
    }
    Labelinfo.Text = "Post successful."; 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Basically, what I'm trying to create is a page of div tags, each has
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I've got a string that has curly quotes in it. I'd like to replace
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I have a small JavaScript validation script that validates inputs based on Regex. I
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have a French site that I want to parse, but am running into
In my XML file chapters tag has more chapter tag.i need to display chapters

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.