Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    New to the CF scene
    Join Date
    Jun 2012
    Location
    Bloomington, IN
    Posts
    6
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Need Help Inserting ID

    Hello everyone! I am new to the form and looking for some help. I am working at a local newspaper as a web programmer and my current project is giving me some trouble. Here is the situation, I am making a form for users to input data on alumni but when I go to insert the data it fails because it needs a value for the id field. I am in Visual Studio 2010. Here is my code:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;

    public partial class alumni_faq_add_alumni : System.Web.UI.Page
    {
    protected void Page_Load(object sender, EventArgs e)
    {
    // //if id is not null in querystring, load alumni data
    // directoriesDataContext db = new directoriesDataContext();
    // int id = Convert.ToInt32(Request.QueryString["id"]);
    // var peoplequery = from q in db.peoples
    // join s in db.peoples on q.name equals s.id
    // where q.id == id
    // select q;
    // if (id !== null)
    // {
    // foreach (var q in peoplequery)
    // {
    // peoplequery.Text = q.id;
    // }
    // }
    }
    protected void btnSubmitClick(object sender, EventArgs e)
    {
    //two different options: if the is edit alumni or new alumni (if/else)
    directoriesDataContext db = new directoriesDataContext();
    int id = Convert.ToInt32(Request.QueryString["id"]);
    //if (id == null)
    {
    people person = new people();
    person.name = TextBox1.Text;
    person.current_employer = TextBox2.Text;
    person.ids_role = TextBox3.Text;
    person.location_name = TextBox4.Text;
    person.description = "Alumni";
    person.position = TextBox5.Text;
    person.id =

    if (FileUpload1.HasFile)
    try
    {
    FileUpload1.SaveAs(Server.MapPath("..\\..\\..\\news\\Directories\\picture\\people\\") + FileUpload1.FileName);
    LitUpLd.Text = "File name: " + FileUpload1.PostedFile.FileName + " (" + FileUpload1.PostedFile.ContentLength + "kb) " + "Content type; " + FileUpload1.PostedFile.ContentType;
    }
    catch (Exception ex)
    {
    LitUpLd.Text = "ERROR: " + ex.Message.ToString();
    }
    db.peoples.InsertOnSubmit(person);
    db.SubmitChanges();
    }

    }

    }

  • #2
    Senior Coder alykins's Avatar
    Join Date
    Apr 2011
    Posts
    1,662
    Thanks
    41
    Thanked 189 Times in 188 Posts
    !== is not a legal C# operator-
    This line is not correct:
    person.id =
    it will throw an error-

    what does your table look like- is the 'id' field the primary key? is it an identity field? if it is PK, and is identity, then don't try to assign anything to it- SQL will take care of it... if it is PK and not identity field- you should probably change it to be identity field and let SQL take care of it... if it is not PK or identity field, then you need to get the id from somewhere- add a textbox or something on the page that needs filled out

    I code C hash-tag .Net
    Reference: W3C W3CWiki .Net Lib
    Validate: html CSS
    Debug: Chrome FireFox IE

  • Users who have thanked alykins for this post:

    IndianaStudent (07-16-2012)

  • #3
    New to the CF scene
    Join Date
    Jun 2012
    Location
    Bloomington, IN
    Posts
    6
    Thanks
    1
    Thanked 0 Times in 0 Posts
    I left person.id blank because I was having trouble, if I comment it out I still get an error. How do I check what is the PK in SQL Server management studio? I am really green at this stuff and the person that was supposed to help me out quit so I am by myself on all this stuff.

    Thanks for the help

  • #4
    Senior Coder alykins's Avatar
    Join Date
    Apr 2011
    Posts
    1,662
    Thanks
    41
    Thanked 189 Times in 188 Posts
    expand table, expand columns (primary keys will be golden key, foreign will be grey)
    also can expand the "Keys" folder
    Attached Thumbnails Attached Thumbnails Need Help Inserting ID-keys.png  

    I code C hash-tag .Net
    Reference: W3C W3CWiki .Net Lib
    Validate: html CSS
    Debug: Chrome FireFox IE

  • #5
    New to the CF scene
    Join Date
    Jun 2012
    Location
    Bloomington, IN
    Posts
    6
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Awesome. So the PK is the id column and the organization id is the FK.

  • #6
    Senior Coder alykins's Avatar
    Join Date
    Apr 2011
    Posts
    1,662
    Thanks
    41
    Thanked 189 Times in 188 Posts
    I don't know- no clue what your tables look like- learning DB schemas and architectures is in depth and requires more than just a thread--i don't see anything with the word "organization" in it- no idea what you're talking about :|

    I code C hash-tag .Net
    Reference: W3C W3CWiki .Net Lib
    Validate: html CSS
    Debug: Chrome FireFox IE

  • #7
    New to the CF scene
    Join Date
    Jun 2012
    Location
    Bloomington, IN
    Posts
    6
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Oh, yes I forgot to tell you that I had fixed the key problem. Now I am working on an issue with the file upload. It is saying that I Cannot use a leading .. to exit above the top directory. I am thinking this is a problem I will have to deal with myself? Thanks for your help everyone!


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •