Sending email... incorrect value(parameter) comes back

Sending email... incorrect value(parameter) comes back

am 15.01.2008 21:02:10 von JJ297

The user selects an item from the gridview which takes them to
checkoutitem.aspx (this works well)

Protected Sub GridView1_SelectedIndexChanged(ByVal sender As Object,
ByVal e As System.EventArgs) Handles GridView1.SelectedIndexChanged
Response.Redirect("checkoutItem.aspx?TitleID=" &
GridView1.SelectedValue)

End Sub

I'm able to fill out the form then the email is sent. I get the email
but the correct titleid is not there.

Protected Sub Submit_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Submit.Click

Dim PhoneNum As String = PhNoTxt.Text

Dim Job As String = JobTxt.Text

Dim StreetAddress1 As String = Street1Txt.Text

Dim StreetAddress2 As String = Street2Txt.Text

Dim City As String = CityTxt.Text

Dim State As String = StateTxt.Text

Dim Zip As String = ZipcodeTxt.Text

Dim ZipPlus As String = ZipPlusTxt.Text

Dim conn As New
Data.SqlClient.SqlConnection(ConfigurationManager.Connection Strings("TrainUserConnectionString").ConnectionString)

Dim cmd As New Data.SqlClient.SqlCommand

With cmd

..Connection = conn 'the connection

..CommandType = Data.CommandType.StoredProcedure

..CommandText = "AddLoanRequest"

..Parameters.AddWithValue("@RequestorEmail", EmailAdd.Text)

..Parameters.AddWithValue("@RequestDate", LoanDate.Text)

..Parameters.AddWithValue("@FName", FName.Text)

..Parameters.AddWithValue("@LName", LName.Text)

..Parameters.AddWithValue("@PhoneNum", PhNoTxt.Text)

..Parameters.AddWithValue("@JobTitleID", JobTxt.Text)

..Parameters.AddWithValue("@StreetAddress1", Street1Txt.Text)

..Parameters.AddWithValue("@StreetAddress2", Street2Txt.Text)

..Parameters.AddWithValue("@City", CityTxt.Text)

..Parameters.AddWithValue("@State", StateTxt.Text)

..Parameters.AddWithValue("@Zip", ZipcodeTxt.Text)

..Parameters.AddWithValue("@ZipPlus4", ZipPlusTxt.Text)


End With

'Try

conn.Open()

Dim x As Integer

x = cmd.ExecuteNonQuery

Dim ocdoEmail As New Object

ocdoEmail = Server.CreateObject("CDO.Message")

ocdoEmail.To = Session("GetEmail")

ocdoEmail.From = Session("GetEmail")

'ocdoEmail.CC

ocdoEmail.Subject = "Training Library Request"

ocdoEmail.HTMLBody = " traininglibrary/Fillrequest.aspx?TitleID=" & x & """>Click to view a>"

ocdoEmail.send()


conn.Close()

End Sub


Here's the stored procedure AddLoanRequest

CREATE procedure AddLoanRequest
@RequestorEmail varchar (75),
@RequestDate datetime,
@Fname varchar (50),
@Lname varchar (50),
@PhoneNum char (10),
@JobTitleID int,
@StreetAddress1 varchar (50),
@StreetAddress2 varchar (50),
@City varchar (50),
@State char (2),
@Zip char (5),
@ZipPlus4 char (4)
AS

set NOCOUNT on
declare @TitleID int

insert into Requestors(RequestorEmail, Titleid,RequestDate,
Fname,Lname,PhoneNum,JobTitleId,StreetAddress1,StreetAddress 2,City,State,Zip,ZipPlus4)
values(@RequestorEmail,
@Titleid,
@RequestDate,
@Fname,
@Lname,
@PhoneNum,
@JobTitleID,
@StreetAddress1,
@StreetAddress2,
@City,
@State,
@Zip,
@ZipPlus4)
set @titleid = SCOPE_IDENTITY() --grabbing the id

select @titleid as titleid --return to caller for email

GO




Is the ocdoEmail.HTMLBody correct? Do I need to put something on
Fillrequest.aspx?

Re: Sending email... incorrect value(parameter) comes back

am 15.01.2008 21:10:49 von sloan

I'd suggest seperating out your code to a library, instead of mixing it in
so tightly.

Why are you
> conn.Open()
to send an email?

That looks very quirky.

I'd download the code here
http://sholliday.spaces.live.com/blog/cns!A68482B9628A842A!1 38.entry
and get the email part working, before intertwining it with db update code..


Or go here:
http://www.systemwebmail.com/




"JJ297" wrote in message
news:b6541cdb-2c27-4390-93a8-e15c2754a4fa@d4g2000prg.googleg roups.com...
> The user selects an item from the gridview which takes them to
> checkoutitem.aspx (this works well)
>
> Protected Sub GridView1_SelectedIndexChanged(ByVal sender As Object,
> ByVal e As System.EventArgs) Handles GridView1.SelectedIndexChanged
> Response.Redirect("checkoutItem.aspx?TitleID=" &
> GridView1.SelectedValue)
>
> End Sub
>
> I'm able to fill out the form then the email is sent. I get the email
> but the correct titleid is not there.
>
> Protected Sub Submit_Click(ByVal sender As Object, ByVal e As
> System.EventArgs) Handles Submit.Click
>
> Dim PhoneNum As String = PhNoTxt.Text
>
> Dim Job As String = JobTxt.Text
>
> Dim StreetAddress1 As String = Street1Txt.Text
>
> Dim StreetAddress2 As String = Street2Txt.Text
>
> Dim City As String = CityTxt.Text
>
> Dim State As String = StateTxt.Text
>
> Dim Zip As String = ZipcodeTxt.Text
>
> Dim ZipPlus As String = ZipPlusTxt.Text
>
> Dim conn As New
> Data.SqlClient.SqlConnection(ConfigurationManager.Connection Strings("TrainUserConnectionString").ConnectionString)
>
> Dim cmd As New Data.SqlClient.SqlCommand
>
> With cmd
>
> .Connection = conn 'the connection
>
> .CommandType = Data.CommandType.StoredProcedure
>
> .CommandText = "AddLoanRequest"
>
> .Parameters.AddWithValue("@RequestorEmail", EmailAdd.Text)
>
> .Parameters.AddWithValue("@RequestDate", LoanDate.Text)
>
> .Parameters.AddWithValue("@FName", FName.Text)
>
> .Parameters.AddWithValue("@LName", LName.Text)
>
> .Parameters.AddWithValue("@PhoneNum", PhNoTxt.Text)
>
> .Parameters.AddWithValue("@JobTitleID", JobTxt.Text)
>
> .Parameters.AddWithValue("@StreetAddress1", Street1Txt.Text)
>
> .Parameters.AddWithValue("@StreetAddress2", Street2Txt.Text)
>
> .Parameters.AddWithValue("@City", CityTxt.Text)
>
> .Parameters.AddWithValue("@State", StateTxt.Text)
>
> .Parameters.AddWithValue("@Zip", ZipcodeTxt.Text)
>
> .Parameters.AddWithValue("@ZipPlus4", ZipPlusTxt.Text)
>
>
> End With
>
> 'Try
>
> conn.Open()
>
> Dim x As Integer
>
> x = cmd.ExecuteNonQuery
>
> Dim ocdoEmail As New Object
>
> ocdoEmail = Server.CreateObject("CDO.Message")
>
> ocdoEmail.To = Session("GetEmail")
>
> ocdoEmail.From = Session("GetEmail")
>
> 'ocdoEmail.CC
>
> ocdoEmail.Subject = "Training Library Request"
>
> ocdoEmail.HTMLBody = "
> traininglibrary/Fillrequest.aspx?TitleID=" & x & """>Click to view > a>"
>
> ocdoEmail.send()
>
>
> conn.Close()
>
> End Sub
>
>
> Here's the stored procedure AddLoanRequest
>
> CREATE procedure AddLoanRequest
> @RequestorEmail varchar (75),
> @RequestDate datetime,
> @Fname varchar (50),
> @Lname varchar (50),
> @PhoneNum char (10),
> @JobTitleID int,
> @StreetAddress1 varchar (50),
> @StreetAddress2 varchar (50),
> @City varchar (50),
> @State char (2),
> @Zip char (5),
> @ZipPlus4 char (4)
> AS
>
> set NOCOUNT on
> declare @TitleID int
>
> insert into Requestors(RequestorEmail, Titleid,RequestDate,
> Fname,Lname,PhoneNum,JobTitleId,StreetAddress1,StreetAddress 2,City,State,Zip,ZipPlus4)
> values(@RequestorEmail,
> @Titleid,
> @RequestDate,
> @Fname,
> @Lname,
> @PhoneNum,
> @JobTitleID,
> @StreetAddress1,
> @StreetAddress2,
> @City,
> @State,
> @Zip,
> @ZipPlus4)
> set @titleid = SCOPE_IDENTITY() --grabbing the id
>
> select @titleid as titleid --return to caller for email
>
> GO
>
>
>
>
> Is the ocdoEmail.HTMLBody correct? Do I need to put something on
> Fillrequest.aspx?