•
•
•
•
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
![]() |
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
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
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
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
•
•
Join Date: Sep 2007
Posts: 1,054
Reputation:
Rep Power: 3
Solved Threads: 61
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.
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
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
•
•
Join Date: Sep 2007
Posts: 1,054
Reputation:
Rep Power: 3
Solved Threads: 61
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
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
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
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
![]() |
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
•
•
•
•
•
•
•
•
DaniWeb ASP.NET Marketplace
- Previous Thread: login validation
- Next Thread: session



Linear Mode