I am working on a web application. I have two text boxes, one is txtEmployeeID
, and one is txtEmployeeName
. What I am trying to do here is when the user enter EmployeeID
in the txtEmployeeID
, the name of the employee will show up in the txtEmployeeName
. I got this part working so far. However, if the employeeID
start with bunch of 0
, let say 00000345
, the user need to enter all 00000345
in the employeeID
in order to show that employeeName
. I am wondering if there a way for user to just enter 345
and then that 00000345
's employeeName
will display in the txtEmployeeName
? Help will be appreaciated.
For Example
EmployeeID EmployeeName
00000345 James Murray
In my text box.
Employee ID: 345
It will display
Employee Name: James Murray
My DB Query
@Employee_ID varchar(8) = NULL
SELECT s.Employee_ID, p.FIRST_NAME, p.LAST_NAME
FROM [dbo].[Employee] e INNER JOIN [dbo].[Person] p ON e.PERSON_ID = p.PERSON_ID
WHERE p.Employee_ID = @Employee_ID
Zeros are ignored at the start of an int . If you need the zeros to be displayed, store the number as a String instead. If you need to use it for calculations later, you can convert it to an int using Integer.
The cin. ignore() function is used which is used to ignore or clear one or more characters from the input buffer.
Use str. Call str. strip(chars) on a string with "0" as chars to remove zeros from the beginning and end of the string.
Try this
int num = Convert.ToInt32(txtEmployeeID.Text);
string idNum = num.ToString("00000000");
txtEmployeeID.Text = idNum.ToString();
You can use Int32.ToString("000") to format an integer in this manner. For details, see Custom Numeric Format Strings and Int32.ToString:
txtEmployeeID.text.ToString("00000000") == EmployeeID;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With