Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

ASP.NET Forum


You are currently viewing our ASP.NET Forum as a guest. Please register to participate.
Login



Reply
How can i get rid of this error.
Old 11-01-2010, 12:00 PM How can i get rid of this error.
Average Talker

Posts: 23
Name: Robert Morgan
Trades: 0
I keep getting this code when i try to submit my form:

HTML Code:
Server Error in '/facultyachievements' Application.

Conversion from type 'DBNull' to type 'Integer' is not valid.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: System.InvalidCastException: Conversion from type 'DBNull' to type 'Integer' is not valid.

Source Error: 


Line 35: 
Line 36:     Protected Sub SqlDataSource3_Inserted(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.SqlDataSourceStatusEventArgs) Handles SqlDataSource3.Inserted
Line 37:         SendMail(e.Command.Parameters("@ID").Value)
Line 38:     End Sub
Line 39: 

Source File: C:\inetpub\wwwroot\PRODdickinsonstate\facultyachievements\submit.aspx.vb    Line: 37 

Stack Trace: 


[InvalidCastException: Conversion from type 'DBNull' to type 'Integer' is not valid.]
   Microsoft.VisualBasic.CompilerServices.Conversions.ToInteger(Object Value) +953
   submit.SqlDataSource3_Inserted(Object sender, SqlDataSourceStatusEventArgs e) in C:\inetpub\wwwroot\PRODdickinsonstate\facultyachievements\submit.aspx.vb:37
   System.Web.UI.WebControls.SqlDataSourceView.OnInserted(SqlDataSourceStatusEventArgs e) +95
   System.Web.UI.WebControls.SqlDataSourceView.ExecuteDbCommand(DbCommand command, DataSourceOperation operation) +355
   System.Web.UI.WebControls.SqlDataSourceView.ExecuteInsert(IDictionary values) +227
   System.Web.UI.WebControls.SqlDataSource.Insert() +16
   submit.btnSubmit_Click(Object sender, EventArgs e) in C:\inetpub\wwwroot\PRODdickinsonstate\facultyachievements\submit.aspx.vb:12
   System.Web.UI.WebControls.Button.OnClick(EventArgs e) +111
   System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +110
   System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10
   System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13
   System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +36
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1565

Here is the vb code that the error is generated in:
Code:
Imports System.Net.Mail
Imports System.Data

Partial Class submit
    Inherits System.Web.UI.Page

    Private Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

    End Sub

    Protected Sub btnSubmit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSubmit.Click
        SqlDataSource3.Insert()
    End Sub

    Protected Sub SqlDataSource3_Inserting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.SqlDataSourceCommandEventArgs) Handles SqlDataSource3.Inserting
        'upload attachment first so that if it fails, record won't be inserted

        'see if a file needs to be uploaded, otherwise, this part can be skipped
        If uplAttachment.FileName <> "" Then

            Dim strPath As String = "C:\inetpub\wwwroot\dickinsonstate\facultyachievements\attachments\"
            Dim strFileName As String = uplAttachment.FileName 'name of file
            Dim n As Integer = Nothing

            'first, if the file exists, append n to the file name
            'if strFileName & n exists, increment n until a unique file name is created
            Do While System.IO.File.Exists(strPath & strFileName)
                strFileName = strFileName.Insert(strFileName.IndexOf("."), n.ToString)
                n += 1
            Loop
            uplAttachment.SaveAs(strPath & strFileName)
            e.Command.Parameters("@attachment").Value = strFileName.ToString
        End If
    End Sub

    Protected Sub SqlDataSource3_Inserted(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.SqlDataSourceStatusEventArgs) Handles SqlDataSource3.Inserted
     Error   ---->SendMail(e.Command.Parameters("@ID").Value)<------Error
    End Sub

    Public Sub SendMail(ByVal id As Integer)

        'SqlDataSource3.SelectCommand = "SELECT * FROM [facultynews] WHERE [ID] = " & id.ToString
        SqlDataSource3.SelectParameters.Item("ID").DefaultValue = id
        Dim reader As SqlClient.SqlDataReader = SqlDataSource3.Select(DataSourceSelectArguments.Empty)

        Dim ThisHost As String = "smtp Port area"
        Dim ThisPort As Integer = port 
        Dim TheseCredentials As New Net.NetworkCredential("emailID", "password")

        Dim NetMail As New MailMessage
        Dim MailClient As New SmtpClient
        MailClient.DeliveryMethod = SmtpDeliveryMethod.Network
        MailClient.Host = ThisHost
        MailClient.Port = ThisPort
        MailClient.EnableSsl = True
        MailClient.UseDefaultCredentials = False
        MailClient.Credentials = TheseCredentials

        Dim ThisSender As String = "DSU Form Mailer <dsu.form.mailer@dsu.nodak.edu>"

        'email to admin
        Dim ThisRecipient As String = "kathy.jorgenson@dsu.nodak.edu"
        Dim ThisBccRecipient As String = "robert.morgan@dsu.nodak.edu"

        'email info: subject, body, to, from, etc
        Dim strBody As String 'Strings for recipient, subject, boby
        strBody = "<strong>Faculty Achievement Submission</strong><br />Click here to view the submission: <a href='http://www.dickinsonstate.edu/facultyachievements/admin/facultynews/Details.aspx?ID=" & id.ToString & "'>http://www.dickinsonstate.edu/facultyachievements/admin/facultynews/Details.aspx?ID=" & id.ToString & "</a>"
        NetMail.From = New MailAddress(ThisSender)
        NetMail.To.Add(New MailAddress(ThisRecipient))
        NetMail.Bcc.Add(New MailAddress(ThisBccRecipient))
        NetMail.Subject = "Faculty Achievement"
        NetMail.IsBodyHtml = True
        NetMail.Body = strBody

        MailClient.Send(NetMail)

        'email to user
        NetMail.To.Clear()

        reader.Read()
        ThisRecipient = reader("email")

        'email info: subject, body, to, from, etc
        strBody = "Thank you, " & reader("title") & " " & reader("fname").ToString & " " & reader("lname").ToString & "!<br /><br />Your faculty achievement submission has been received.<br /><br />Please contact the Office of University Relations if you have any further questions."
        NetMail.To.Add(New MailAddress(ThisRecipient))
        NetMail.Subject = "Faculty Achievement Submission"
        NetMail.IsBodyHtml = True
        NetMail.Body = strBody

        MailClient.Send(NetMail)

        Response.Redirect("thanks.aspx")

    End Sub
End Class
robertpurpose is offline
Reply With Quote
View Public Profile Visit robertpurpose's homepage!
 
 
Register now for full access!
Reply     « Reply to How can i get rid of this error.
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.87730 seconds with 12 queries