 |
| ASP.NET 3.5 Basics If you are new to ASP or ASP.NET programming with version 3.5, this is the forum to begin asking questions. Please also see the Visual Web Developer 2008 forum. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the ASP.NET 3.5 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
|

August 6th, 2009, 11:13 AM
|
|
Authorized User
|
|
Join Date: Jun 2009
Posts: 30
Thanks: 13
Thanked 0 Times in 0 Posts
|
|
Display employer id
hi....how to display the last data(Employer ID) from employer table?
selectStr = "Select Employer_Id from Employer";
cmdSelect = newSqlCommand(selectStr, con);
dtrEmp = cmdSelect.ExecuteReader();
if (dtrEmp.HasRows){
while (dtrEmp.Read())
{
Label2.Text = Convert.ToString(dtrEmp["Employer_Id"]);
}
}
dtrEmp.Close();
i have tried....but still could get the last Employer_Id...can anybody correct it?
Last edited by Banishah; August 6th, 2009 at 11:28 AM..
|
|

August 6th, 2009, 03:02 PM
|
 |
Wrox Author
|
|
Join Date: Jan 2008
Posts: 923
Thanks: 12
Thanked 166 Times in 162 Posts
|
|
You should be able to do that by using the Read method as you have.
This should work:
Code:
using (SqlConnection connection = new SqlConnection("your_connection_string"))
{
string cmdText = "SELECT Employer_Id FROM Employer";
SqlCommand command = new SqlCommand(cmdText, connection);
connection.Open();
SqlDataReader reader = command.ExecuteReader();
if (reader != null)
while (reader.Read())
{
Label2.Text = reader["Employer_Id"].ToString();
}
}
|
|
The Following User Says Thank You to Lee Dumond For This Useful Post:
|
|
|

August 6th, 2009, 03:16 PM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
|
|
Sorry Lee, But I see no difference between you code and OP's code. Maybe he need to clarify what is he looking for??? I think he is looking for a max function or a min one or something like httat. Anyway he will still show always the last ID of the table, with no particular order.
__________________
HTH
Gonzalo
================================================== =========
Read this if you want to know how to get a correct reply for your question.
(Took that from Doug signature and he Took that from Peter profile)
================================================== =========
My programs achieved a new certification :
WORKS ON MY MACHINE
================================================== =========
I know that CVS was evil, and now i got the proof.
================================================== =========
|
|

August 6th, 2009, 03:45 PM
|
 |
Wrox Author
|
|
Join Date: Jan 2008
Posts: 923
Thanks: 12
Thanked 166 Times in 162 Posts
|
|
Quote:
Originally Posted by gbianchi
Sorry Lee, But I see no difference between you code and OP's code.
|
Maybe you should look closer.
His code never calls the Open method to open the connection.
|
|

August 6th, 2009, 03:57 PM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
|
|
Yep that right, but he doesn't instanciate the connection either, so he could easily has open it before all this...
Anyway, I was just asking because it's not clear what the porpuose of his code.. Maybe Banishah can tell us what he is looking for to do???
__________________
HTH
Gonzalo
================================================== =========
Read this if you want to know how to get a correct reply for your question.
(Took that from Doug signature and he Took that from Peter profile)
================================================== =========
My programs achieved a new certification :
WORKS ON MY MACHINE
================================================== =========
I know that CVS was evil, and now i got the proof.
================================================== =========
|
|

August 7th, 2009, 11:52 PM
|
|
Authorized User
|
|
Join Date: Jun 2009
Posts: 30
Thanks: 13
Thanked 0 Times in 0 Posts
|
|
Actually i need the last employerID(e.g EM000003) to add 1 to it and become EM000004 because i want it to be autogenerated once a new employer is added....
|
|

August 8th, 2009, 02:02 PM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
|
|
So in your ID field you have a combo of letters and numbers??
well this just complicate things. Several things you can do is split the field, get the max of the numbers and add one (all in one query).
__________________
HTH
Gonzalo
================================================== =========
Read this if you want to know how to get a correct reply for your question.
(Took that from Doug signature and he Took that from Peter profile)
================================================== =========
My programs achieved a new certification :
WORKS ON MY MACHINE
================================================== =========
I know that CVS was evil, and now i got the proof.
================================================== =========
|
|

August 9th, 2009, 01:05 AM
|
|
Authorized User
|
|
Join Date: Jun 2009
Posts: 30
Thanks: 13
Thanked 0 Times in 0 Posts
|
|
But how to split it?
|
|

August 9th, 2009, 04:23 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
Isn't this simply a matter of presentation and formatting?
I would create an identity field that automatically increases on each new record. Then either in your presentation layer or in a calculated field you combine the EM0000* stuff with the employee id...
Just my 2 cents.
Imar
|
|
The Following User Says Thank You to Imar For This Useful Post:
|
|
|
 |