View Full Version : Need Help Inserting ID

07-13-2012, 08:39 PM
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)
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();



07-13-2012, 09:09 PM
!== 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

07-16-2012, 04:04 PM
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

07-16-2012, 04:35 PM
expand table, expand columns (primary keys will be golden key, foreign will be grey)
also can expand the "Keys" folder

07-16-2012, 05:00 PM
Awesome. So the PK is the id column and the organization id is the FK.

07-16-2012, 07:27 PM
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 :|

07-16-2012, 08:21 PM
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!

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum