User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the ASP.NET section within the Web Development category of DaniWeb, a massive community of 375,193 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,172 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our ASP.NET advertiser: Lunarpages ASP Web Hosting
Views: 2828 | Replies: 140
Reply
Join Date: Feb 2008
Location: Va Beach
Posts: 179
Reputation: foundsheep is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
foundsheep's Avatar
foundsheep foundsheep is offline Offline
Junior Poster

Re: Insert to DB & View Results on Different Page

  #21  
Feb 19th, 2008
On that last code you posted ...

Server Error in '/HRIService' Application.
Compilation Error
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

Compiler Error Message: BC30002: Type 'SqlException' is not defined.

Source Error:

Line 71: reader.Close()
Line 72: connection.Close()
Line 73: Catch ex As SqlException
Line 74: End Try
Line 75:


Source File: C:\Inetpub\wwwroot\HRIService\ServiceExpress\AddCall.aspx.vb Line: 73
Reply With Quote  
Join Date: Sep 2007
Posts: 1,054
Reputation: SheSaidImaPregy is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 61
SheSaidImaPregy SheSaidImaPregy is offline Offline
Veteran Poster

Re: Insert to DB & View Results on Different Page

  #22  
Feb 19th, 2008
That's odd. Aren't you using ms sql? Anyway, that doesn't matter. Just change the line 73 to:

Catch
Reply With Quote  
Join Date: Feb 2008
Location: Va Beach
Posts: 179
Reputation: foundsheep is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
foundsheep's Avatar
foundsheep foundsheep is offline Offline
Junior Poster

Re: Insert to DB & View Results on Different Page

  #23  
Feb 19th, 2008
On the add new company page I got:

Server Error in '/HRIService' Application.
Compilation Error
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

Compiler Error Message: BC30451: Name 'cusID' is not declared.

Source Error:

Line 58: End Try
Line 59:
Line 60: Response.Redirect("default.aspx?cusID=" & cusID & "&conID=" & conID)
Line 61:
Line 62: End Sub


Source File: C:\Inetpub\wwwroot\HRIService\ServiceExpress\DisAddCo.aspx.vb Line: 60
Reply With Quote  
Join Date: Sep 2007
Posts: 1,054
Reputation: SheSaidImaPregy is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 61
SheSaidImaPregy SheSaidImaPregy is offline Offline
Veteran Poster

Re: Insert to DB & View Results on Different Page

  #24  
Feb 19th, 2008
I think that means your try/catch is failing, otherwise it would have been set. Here, do this code:
Imports System
Imports System.Configuration
Imports System.Data.SqlClient
Imports System.Web.UI.WebControls

Partial Public Class DisAddCo
    Inherits System.Web.UI.Page
    Protected Sub FormView1_ItemInserting(ByVal sender As Object, ByVal e As FormViewInsertEventArgs)
        ' Retrieve controls
        Dim CompanyTextBox As TextBox = TryCast(FormView1.FindControl("CompanyTextBox"), TextBox)
        Dim FirstNameTextBox As TextBox = TryCast(FormView1.FindControl("FirstNameTextBox"), TextBox)
        Dim LastNameTextBox As TextBox = TryCast(FormView1.FindControl("LastNameTextBox"), TextBox)
        Dim Address1TextBox As TextBox = TryCast(FormView1.FindControl("Address1TextBox"), TextBox)
        Dim Address2TextBox As TextBox = TryCast(FormView1.FindControl("Address2TextBox"), TextBox)
        Dim CityTextBox As TextBox = TryCast(FormView1.FindControl("CityTextBox"), TextBox)
        Dim StateTextBox As TextBox = TryCast(FormView1.FindControl("StateTextBox"), TextBox)
        Dim ZipTextBox As TextBox = TryCast(FormView1.FindControl("ZipTextBox"), TextBox)
        Dim PhoneTextBox As TextBox = TryCast(FormView1.FindControl("PhoneTextBox"), TextBox)

        If CompanyTextBox Is Nothing Then Return
        If FirstNameTextBox Is Nothing Then Return
        If LastNameTextBox Is Nothing Then Return
        If Address1TextBox Is Nothing Then Return
        If CityTextBox Is Nothing Then Return
        If StateTextBox Is Nothing Then Return
        If ZipTextBox Is Nothing Then Return
        If PhoneTextBox Is Nothing Then Return

        Dim conn As New SqlConnection(ConfigurationManager.ConnectionStrings("HRIServiceConnectionString1").ConnectionString)

        Dim cmd As New SqlCommand("INSERT INTO [Customers] ([Company], [Address1], [Address2], [Phone]) VALUES (@Company, @Address1, @Address2, @Phone); SELECT SCOPE_IDENTITY();", conn)
        cmd.Parameters.AddWithValue("@Company", CompanyTextBox.Text)
        cmd.Parameters.AddWithValue("@Address1", Address1TextBox.Text)
        cmd.Parameters.AddWithValue("@Address2", Address2TextBox.Text)
        cmd.Parameters.AddWithValue("@Phone", PhoneTextBox.Text)

        Try
            conn.Open()

            Dim cusID As Integer = Convert.ToInt32(cmd.ExecuteScalar())

            cmd = New SqlCommand("INSERT INTO [Contacts] ([cusID], [FirstName], [LastName]) VALUES (@cusID, @FirstName, @LastName); SELECT SCOPE_IDENTITY();", conn)
            cmd.Parameters.AddWithValue("@cusID", cusID)
            cmd.Parameters.AddWithValue("@FirstName", FirstNameTextBox.Text)
            cmd.Parameters.AddWithValue("@LastName", LastNameTextBox.Text)

            Dim conID As Integer = Conver.ToInt32(cmd.ExecuteScalar())

            cmd = New SqlCommand("INSERT INTO [Zip] ([cusID], [City], [State], [Zip]) VALUES (@cusID, @City, @State, @Zip)", conn)
            cmd.Parameters.AddWithValue("@cusID", cusID)
            cmd.Parameters.AddWithValue("@City", CityTextBox.Text)
            cmd.Parameters.AddWithValue("@State", StateTextBox.Text)
            cmd.Parameters.AddWithValue("@Zip", ZipTextBox.Text)

            cmd.ExecuteNonQuery()

            If conn.State = System.Data.ConnectionState.Open Then conn.Close()

            Response.Redirect("default.aspx?cusID=" & cusID & "&conID=" & conID)
        Catch ex As System.Data.SqlException
            Response.Write(ex)
        Finally
            If conn.State = System.Data.ConnectionState.Open Then conn.Close()
        End Try

    End Sub

End Class
Last edited by SheSaidImaPregy : Feb 19th, 2008 at 12:00 pm.
Reply With Quote  
Join Date: Sep 2007
Posts: 1,054
Reputation: SheSaidImaPregy is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 61
SheSaidImaPregy SheSaidImaPregy is offline Offline
Veteran Poster

Re: Insert to DB & View Results on Different Page

  #25  
Feb 19th, 2008
Oh and the reason why SqlException wasn't working before is because you're doing code-behind, which means you needed:

System.Data.SqlException
Reply With Quote  
Join Date: Feb 2008
Location: Va Beach
Posts: 179
Reputation: foundsheep is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
foundsheep's Avatar
foundsheep foundsheep is offline Offline
Junior Poster

Re: Insert to DB & View Results on Different Page

  #26  
Feb 19th, 2008
New error:

Server Error in '/HRIService' Application.
Compilation Error
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

Compiler Error Message: BC30002: Type 'System.Data.SqlException' is not defined.

Source Error:

Line 58:
Line 59: Response.Redirect("default.aspx?cusID=" & cusID & "&conID=" & conID)
Line 60: Catch ex As System.Data.SqlException
Line 61: Response.Write(ex)
Line 62: Finally


Source File: C:\Inetpub\wwwroot\HRIService\ServiceExpress\DisAddCo.aspx.vb Line: 60
Reply With Quote  
Join Date: Sep 2007
Posts: 1,054
Reputation: SheSaidImaPregy is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 61
SheSaidImaPregy SheSaidImaPregy is offline Offline
Veteran Poster

Re: Insert to DB & View Results on Different Page

  #27  
Feb 19th, 2008
oh cmon lol.

Drop it too I guess.

Change line 60 and 61 to:

Catch
Response.Write("failed")
Reply With Quote  
Join Date: Feb 2008
Location: Va Beach
Posts: 179
Reputation: foundsheep is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
foundsheep's Avatar
foundsheep foundsheep is offline Offline
Junior Poster

Re: Insert to DB & View Results on Different Page

  #28  
Feb 19th, 2008
Ok, I guess I'm missing some code somewhere. I tried to add a new customer but it didn't post to the new ticket page. It just reloaded. I'm guessing it has something to do with the Page_load code.
Reply With Quote  
Join Date: Sep 2007
Posts: 1,054
Reputation: SheSaidImaPregy is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 61
SheSaidImaPregy SheSaidImaPregy is offline Offline
Veteran Poster

Re: Insert to DB & View Results on Different Page

  #29  
Feb 19th, 2008
Nope, check the page for the word "failed". Your update failed, otherwise it would have redirected. Now you have to find out how it failed.

Change line 60 and 61 to:

Catch ex As System.Data.SqlClient.SqlException
Response.write (ex)

Found the error in my code, it was that I was missing SqlClient. :\

Hate code-behind! lol
Reply With Quote  
Join Date: Feb 2008
Location: Va Beach
Posts: 179
Reputation: foundsheep is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
foundsheep's Avatar
foundsheep foundsheep is offline Offline
Junior Poster

Re: Insert to DB & View Results on Different Page

  #30  
Feb 19th, 2008
Here's the error:

Server Error in '/HRIService' Application.
Object cannot be cast from DBNull to other types.
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: Object cannot be cast from DBNull to other types.

Source Error:

Line 45: cmd.Parameters.AddWithValue("@LastName", LastNameTextBox.Text)
Line 46:
Line 47: Dim conID As Integer = Convert.ToInt32(cmd.ExecuteScalar())
Line 48:
Line 49: cmd = New SqlCommand("INSERT INTO [Zip] ([cusID], [City], [State], [Zip]) VALUES (@cusID, @City, @State, @Zip)", conn)


Source File: C:\Inetpub\wwwroot\HRIService\ServiceExpress\DisAddCo.aspx.vb Line: 47
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

DaniWeb ASP.NET Marketplace
Thread Tools Display Modes

Other Threads in the ASP.NET Forum

All times are GMT -4. The time now is 2:09 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC