BobRosas
asked on
Retrieve one specific record in C#
The first part of the attached code works and finds a random RecordId. I also need the EmployeeId. Since there is only one EmpId for each RcdId, I'm trying to find code to retrieve one record with a RecId of txtRcdId (which is the end result of the code).
I added the last 2 lines to try and accomplish this but I get the error...
'Randomizer.TimeClockPlusD ataContext ' does not contain a definition for 'Tables' and no
extension method 'Tables' accepting a first argument of
type 'Randomizer.TimeClockPlusD ataContext ' could be found (are you missing a using
directive or an assembly reference?)
I 'm really new to C# and could really use some detailed help. My environment is Visual Studio, the language is C# and I'm attached to a SQL Server db.
I added the last 2 lines to try and accomplish this but I get the error...
'Randomizer.TimeClockPlusD
extension method 'Tables' accepting a first argument of
type 'Randomizer.TimeClockPlusD
directive or an assembly reference?)
I 'm really new to C# and could really use some detailed help. My environment is Visual Studio, the language is C# and I'm attached to a SQL Server db.
//This works...
var dbTimeClockPlus = new TimeClockPlusDataContext();
var SearchInfo = (from c in dbTimeClockPlus.EmployeeLists where c.Suspend == false select c.RecordId).FirstOrDefault();
Random r = new Random();
int RcdId = SearchInfo == 0 ? 1 : SearchInfo;
RcdId = r.Next(1, RcdId);
txtRcdId.Text = Convert.ToString(RcdId);
//This part does not work...
DataRow[] returnedRows;
returnedRows = dbTimeClockPlus.Tables["EmployeeLists"].Select(txtRcdId);
ASKER
Thank you for your quick response!
I tried your suggestion but still get the same error. Am I missing a definition somewhere. I read that sometimes when you get this error it's because you need...
using System.Linq;
but I have that. Maybe I'm missing something else? This is a newly set up form so maybe I'm missing something basic?
I tried your suggestion but still get the same error. Am I missing a definition somewhere. I read that sometimes when you get this error it's because you need...
using System.Linq;
but I have that. Maybe I'm missing something else? This is a newly set up form so maybe I'm missing something basic?
yes_its_a_linQ_usage;
did_you_try;
DataRow returnedRows = dbTimeClockPlus.Tables["Em ployeeList s"].Select (txtRcdId) ;
or
DataRow[] returnedRows;
returnedRows[0] = dbTimeClockPlus.Tables["Em ployeeList s"].Select (txtRcdId) ;
did_you_try;
DataRow returnedRows = dbTimeClockPlus.Tables["Em
or
DataRow[] returnedRows;
returnedRows[0] = dbTimeClockPlus.Tables["Em
ASKER
I was doing the 2nd way you listed. So I just tried the 1st way. They are both giving me the same error.
if_youve_tried_this_?,
DataRow returnedRows = dbTimeClockPlus.Tables["Em ployeeList s"].Select (txtRcdId) ;
then
there's_a_wrong_in_your_fi rsts_lines ;
//This works...
var dbTimeClockPlus = new TimeClockPlusDataContext() ;
var SearchInfo = (from c in dbTimeClockPlus.EmployeeLi sts where c.Suspend == false select c.RecordId).FirstOrDefault ();
Random r = new Random();
int RcdId = SearchInfo == 0 ? 1 : SearchInfo;
RcdId = r.Next(1, RcdId);
txtRcdId.Text = Convert.ToString(RcdId);
that_if_your_sure_about;
dbTimeClockPlus.Tables["Em ployeeList s"].Select (txtRcdId) ;
DataRow returnedRows = dbTimeClockPlus.Tables["Em
then
there's_a_wrong_in_your_fi
//This works...
var dbTimeClockPlus = new TimeClockPlusDataContext()
var SearchInfo = (from c in dbTimeClockPlus.EmployeeLi
Random r = new Random();
int RcdId = SearchInfo == 0 ? 1 : SearchInfo;
RcdId = r.Next(1, RcdId);
txtRcdId.Text = Convert.ToString(RcdId);
that_if_your_sure_about;
dbTimeClockPlus.Tables["Em
ASKER
I'm not sure what I'm looking for. If I run the following code all by itself...
var dbTimeClockPlus = new TimeClockPlusDataContext() ;
var SearchInfo = (from c in dbTimeClockPlus.EmployeeLi sts where c.Suspend == false select c.RecordId).FirstOrDefault ();
Random r = new Random();
int RcdId = SearchInfo == 0 ? 1 : SearchInfo;
RcdId = r.Next(1, RcdId);
txtRcdId.Text = Convert.ToString(RcdId);
Then my form displays, I press the button and a random RcdId appear in my text box.
If I add this code to the above code...
DataRow[] returnedRows;
returnedRows[0] = dbTimeClockPlus.Tables["Em ployeeList s"].Select (txtRcdId) ;
I get the above error.
If I add just this one line of code instead of the 2 right above....
DataRow returnedRows = dbTimeClockPlus.Tables["Em ployeeList s"].Select (txtRcdId) ;
I still get the same error.
var dbTimeClockPlus = new TimeClockPlusDataContext()
var SearchInfo = (from c in dbTimeClockPlus.EmployeeLi
Random r = new Random();
int RcdId = SearchInfo == 0 ? 1 : SearchInfo;
RcdId = r.Next(1, RcdId);
txtRcdId.Text = Convert.ToString(RcdId);
Then my form displays, I press the button and a random RcdId appear in my text box.
If I add this code to the above code...
DataRow[] returnedRows;
returnedRows[0] = dbTimeClockPlus.Tables["Em
I get the above error.
If I add just this one line of code instead of the 2 right above....
DataRow returnedRows = dbTimeClockPlus.Tables["Em
I still get the same error.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thank you for your time and the links. Neither one of them look like they can take the result of what I have and display another field from the same record but I do apprecaite you trying and I can try posting another question. Thanks again!
returnedRows[1] = dbTimeClockPlus.Tables["Em