thanks for your comments everyone. i found my answer on another webboard. it was exactly what i was looking for and it works great. see below..
//get the highest primary key value in the datatable. int MaxPKey = Convert.ToInt16(ds.Tables[0].Compute("MAX (pay_adjust_id)","pay_adjust_id <> -1")); //add the new primary key dr["pay_adjust_id"] = MaxPKey + 1; --- In [EMAIL PROTECTED], "Gary Pupurs" <gp- [EMAIL PROTECTED]> wrote: > > > use a guid: > > > System.GUID.NewGuid().ToString() > > > i don't know what that means. > > Look at the VS.NET Documentation, search for "Guid Structure". A GUID is a > globally unique identifier. Typically looks like > "936DA01F-9ABD-4D9D-80C7-02AF85C923A9" in hex ToString() format (though it's > technically just a 128-bit value). You may recognize that format, it's used > all over Windows (in the registry for instance). In SQL Server, this data > type is called "uniqueidentifier", but they're the same. > > > i need to assign a unique value for my primary key > > column in my newly inserted row. how can i do > > this? i need to figure out how to find the max value > > of primary key in my dataset and add a > > 1 to it to have an unused unique value. > > > The confusion here is that you didn't specify clearly that you are using an > integer, your mention of assigning a "unique" value suggested that you may > be using GUIDs. But then you mention adding a one to the value and that > you're not familiar with GUIDs, which leads me to belive your primary key is > an integer, so that's how I'll proceed. > > Let's look at your problem again: > > > To be clear, I want to add a new row to my DataTable, not to my > > actual database. The problem i am running into is that when I > > attempt to do the following.. > > > > DataRow dr= ds.Tables[0].NewRow(); > > dr["pay_adjust_id"] = //needs unique value here for primary key > > dr["pay_adjust_vers_id"] = add_pay_adjust_vers_id; > > dr["ctype_grp_cd"] = add_ctype_grp_cd; > > dr["pay_adjust_type_cd"] = "P"; > > dr["proj_fy"] = add_proj_fy; > > dr["proj_fm"] = add_proj_fm; > > dr["prcnt"] = addPCNT; > > dr["narrative"] = addNAR; > > > > ds.Tables[0].Rows.Add(dr); > > > > it needs a unique value for the primary key. Does anyone know how I > > can come up with a unique value for my primary key column? Thanks! > > You don't need to explicitly assign dr["pay_adjust_id"], there's a better > way. Remove that line, and before the code above, add the following: > > ds.Tables[0].Columns["pay_adjust_id"].AutoIncrement = true; > > Adding a NewRow() should automatically fill the ID column with an > appropriate value. > > In the docs, check out AutoIncrement, AutoIncrementSeed, and > AutoIncrementStep for more info. They're properties of > System.Data.DataColumn. This is also covered in Chapter 12 of Walther's > book, if you have that. > > HTH, > > -g ------------------------ Yahoo! Groups Sponsor --------------------~--> $9.95 domain names from Yahoo!. Register anything. http://us.click.yahoo.com/J8kdrA/y20IAA/yQLSAA/saFolB/TM --------------------------------------------------------------------~-> Yahoo! Groups Links <*> To visit your group on the web, go to: http://groups.yahoo.com/group/AspNetAnyQuestionIsOk/ <*> To unsubscribe from this group, send an email to: [EMAIL PROTECTED] <*> Your use of Yahoo! Groups is subject to: http://docs.yahoo.com/info/terms/