Finding the Lost Identity
-
-
The tblHoliday has two columns. The Name and the Key ID.
timeCardDataSet.tblHoliday.NewtblHolidayRow(); holidayRow.Name = "Name"; timeCardDataSet.tblHoliday.AddtblHolidayRow(holidayRow);
How can I get the value of the (from Access) generated key. -
Are you getting the key from the database? If so, you can use an OleDB Connection, and OleDBCommand object, a connection string, a SELECT statement, and you can use the ExecuteScalar to retrieve the Key.
-
string cmdstr="SELECT Field1 FROM tablename where Field2 = @strField2"; string cons = ; //Look up Connection Strings for Access MDB con=new OleDbConnection(cons); cmd=new OleDbCommand(cmdstr,con); cmd.Parameters.AddWithValue("@strField2",strField2); con.Open(); string myKey = cmd.ExecuteScalar().ToString();