 |
| ASP.NET 1.0 and 1.1 Professional For advanced ASP.NET 1.x coders. Beginning-level questions will be redirected to other forums. NOT for "classic" ASP 3 or the newer ASP.NET 2.0 and 3.5 |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the ASP.NET 1.0 and 1.1 Professional 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
|
|
|
|

July 5th, 2006, 10:09 AM
|
|
Authorized User
|
|
Join Date: Apr 2006
Posts: 56
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
how to email the autogenerated employeeid
In my form once the user fills in the form and hits the submit button an email will be sent out to me with the user id and user's firstname information.
Right now when the user hits the submit button I do receive an email with the user's firatname and lastname. But how do I trap the user id which is autogenerated in the database.I am using C# for my program
Here is the code for email generation while the user hits the submit button-
/**
private void Button1_Click(object sender, System.EventArgs e)
{
Page.Validate();
if (Page.IsValid)
{
EmailForm();
}
}
void EmailForm()
{
string emailTo = ConfigurationSettings.AppSettings["CelInformationEmailTo"].ToString();
string from = ConfigurationSettings.AppSettings["CellInformationEmailFrom"].ToString();
if (emailTo != null)
{
StringBuilder emailBody = new StringBuilder();
emailBody.Append("You have received a new Mail.\n\n");
emailBody.Append("\nFirstname:").Append(txtfirstna me.Text);
MailMessage mailInquiry = new MailMessage();
mailInquiry.To = emailTo;
mailInquiry.From = from;
mailInquiry.Subject = " New Employee";
mailInquiry.Body = emailBody.ToString();
SmtpMail.SmtpServer = ConfigurationSettings.AppSettings["SMTPMailServer"];
SmtpMail.Send(mailInquiry);
}
I would like to know how can I trap the userid and send it in the email.
|
|

July 5th, 2006, 09:31 PM
|
|
Wrox Author
|
|
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
|
|
How are you auto generating the information? Just an [Auto Increment] counter? If that is the case you could create a stored procedure that would preform your database insert and then send you back a return value with your ID:
CREATE PROCEDURE usp_addUser [Parameter here] as
DECLARE @pk int
[INSERT Statement]
Set @pk = (SELECT MAX(PK) from UserTable)
SELECT @pk
Subsitute PK for the name of your column that stores the ID.
BTW, this is TSQL syntax; the syntax for Oracle, MySQL, etc will vary.
"The one language all programmers understand is profanity."
|
|

July 6th, 2006, 11:28 AM
|
|
Authorized User
|
|
Join Date: Apr 2006
Posts: 56
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Thank you for your help.But I have a question.I do understand that in my procedure usp_addUser after the insert statement, I write the Select statement as
Set @pk = (Select Max(PK) from UserTable)----THis part is ok.
But I would like to know how do I assign the value in my program.
Under the Emailform () function if I write -
/*
emailBody.Append("\nUserID:")Append(@User_ID); */
it gives me a error that User_ID not declared.
|
|

July 10th, 2006, 08:54 AM
|
|
Wrox Author
|
|
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
|
|
SELECT @pk is your return value from the stored procedure. So depending on how you return data from your database will determine how you populate this value in your code.
For example, after creating your connection you could do something like this:
Dim paramUserID as New SQLParameter("@PK", sqlDBType.int, 4)
paramUserID.Direction = ParameterDirection.output
Add this command to your parameters list to pass to the stored procedure and then your code would be something like this:
emailBody.Append("\nUserID:" + paramUserID.value + )
Or you could execute the stored procedure and fill a datatable and then populate your string builder like this
emailBody.Append("\nUserID:" + dt.rows(0).item("pk") + )
where dt == datatable.
The reason your @User_ID isnt working is because you cant reference a SQL Variable directly in code, you have to deal with it somehow.
"The one language all programmers understand is profanity."
|
|

July 10th, 2006, 05:50 PM
|
|
Authorized User
|
|
Join Date: Apr 2006
Posts: 56
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Thank you. so much .I got this working
|
|

July 10th, 2006, 05:57 PM
|
|
Friend of Wrox
|
|
Join Date: Jul 2003
Posts: 599
Thanks: 6
Thanked 3 Times in 3 Posts
|
|
How'd you get it working?
Thanks,
Richard
|
|

July 13th, 2006, 12:42 PM
|
|
Authorized User
|
|
Join Date: Apr 2006
Posts: 56
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
I had to pass this code after sqlCommand1.ExecuteNonQuery();
/*int returnValue = (int)sqlCommand1.Parameters["@RETURN_VALUE"].Value;
string userid = sqlCommand1.Parameters["@User_ID"].Value.ToString();*/
This helped me to retieve the User_id in the cs file and store it in the string variable.
|
|

July 27th, 2006, 06:38 AM
|
|
Authorized User
|
|
Join Date: Apr 2006
Posts: 79
Thanks: 1
Thanked 0 Times in 0 Posts
|
|
Hi,
If ur userid is an Identity column in ur table then when u insert the new values into database, write return @@Identity.
It will return the newer generated Identity.
Regards,
Anuj rathi
|
|
 |