Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 1.0 and 1.1 > BOOK: Beginning ASP.NET 1.0
Password Reminder
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
BOOK: Beginning ASP.NET 1.0
This is the forum to discuss the Wrox book Beginning ASP.NET 1.0 with C# by Chris Goode, John Kauffman, Christopher L. Miller, Neil Raybould, S. Srinivasa Sivakumar, Dave Sussman, Ollie Cornes, Rob Birdwell, Matt Butler, Gary Johnson, Ajoy Krishnamoorthy, Juan T. Llibre, Chris Ullman; ISBN: 9780764543708
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning ASP.NET 1.0 section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Thread Tools Display Modes
  #1 (permalink)  
Old July 20th, 2007, 09:26 PM
Registered User
Join Date: Jul 2007
Location: Silver Spring, MD, USA.
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to wtvamp
Default Specified cast is not valid during database insert

I need help with the code below. It's supposed to do a basic database insert, but I keep getting a "Specified cast is not valid. " on the line below in red that says "intLastCustID = CInt(objDR.GetString(0))". Any help would be greatly appreciated.

<%@ Page Language="vb" Debug="true" %><%@ Import namespace="System.Data" %>
<%@ Import Namespace="System.Data.OleDb"%>
<script runat="server">
    Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) ' subroutine to run on page load event

        ' Declaration section
        Dim conClsf As OleDbConnection
        Dim rdrContracts As OleDbDataReader

        conClsf = New OleDbConnection("Provider=MSDAORA.1;" & _
                                      "User ID=cm485a01;" & _
                                      "PassWord=perfect26;" & _
                                      "Data Source=nova;")

        ' Open DB connection

        ' Create new OleDbCommand object with SQL to execute
        Dim cmdContractID = New OleDbCommand("SELECT contractID FROM contract", conClsf)

        ' Create a DataReader and execute the command
        rdrContracts = cmdContractID.ExecuteReader
        contractList.DataSource = rdrContracts
        contractList.DataTextField = "contractID"
        contractList.DataValueField = "contractID"

        cmdContractID = New OleDbCommand("SELECT homeID FROM home", conClsf)
        rdrContracts = cmdContractID.ExecuteReader
        homeList.DataSource = rdrContracts
        homeList.DataTextField = "homeID"
        homeList.DataValueField = "homeID"

        cmdContractID = New OleDbCommand("SELECT agent_ID FROM agent", conClsf)
        rdrContracts = cmdContractID.ExecuteReader
        agentList.DataSource = rdrContracts
        agentList.DataTextField = "agent_ID"
        agentList.DataValueField = "agent_ID"

        cmdContractID = New OleDbCommand("SELECT custID FROM customer", conClsf)
        rdrContracts = cmdContractID.ExecuteReader
        custList.DataSource = rdrContracts
        custList.DataTextField = "custID"
        custList.DataValueField = "custID"

        ' Close all objects

    End Sub

    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs)
        ' Declaration section
        Dim objDBConn As OleDbConnection
        Dim objCmd As OleDbCommand
        Dim objCmd2 As OleDbCommand
        Dim objDR As OleDbDataReader
        Dim strSQL As String
        Dim intLastCustID As Integer
        Dim intNextCustID As Integer

        ' Retrieve parameters from HTML form
        Dim strPrice = Request("price")
        Dim strContactList = Request("contractList")
        Dim strHomeList = Request("homeList")
        Dim strDay = Request("day")
        Dim strMonth = Request("month")
        Dim strYear = Request("year")
        Dim strAgentList = Request("agentList")
        Dim strCustList = Request("custList")

        Response.Write("Price= " & strPrice & "<br>")
        Response.Write("Contact ID= " & strContactList & "<br>")
        Response.Write("Home ID= " & strHomeList & "<br>")
        Response.Write("Day= " & strDay & "<br>")
        Response.Write("Month= " & strMonth & "<br>")
        Response.Write("Year= " & strYear & "<br>")
        Response.Write("Agent ID= " & strAgentList & "<br>")
        Response.Write("Cust ID= " & strCustList & "<br>")

        ' Open DB connection
        objDBConn = New OleDbConnection("Provider=MSDAORA.1;" & _
                                              "User ID=cm485a01;" & _
                                              "PassWord=perfect26;" & _
                                              "Data Source=nova;")

        ' Retrieve highest Cust ID so far and determine next Cust ID
        strSQL = "SELECT MAX(saleID) FROM sale"
        objCmd = New OleDbCommand(strSQL, objDBConn)
        objDR = objCmd.ExecuteReader
        objDR.Read() ' obtain row from results of query)

        intLastCustID = CInt(objDR.GetString(0))
        'Response.Write("Last Sale ID= " & CStr(intLastCustID) & "<br>")
        'intNextCustID = intLastCustID + 1
        'Response.Write("Next Sale ID=" & CStr(intNextCustID) & "<br>")

        '' Set up INSERT statement SQL
        'strSQL = "INSERT INTO sale(saleid,amount,contractid,homeid,saledate,agen t_id,cust_id)VALUES()" & "('" & intNextCustID & "','" & strPrice & "','" & strContactList & "','" & strHomeList & "','" & strDay & "-" & strMonth & "-" & strYear & "','" & strAgentList & "','" & strCustList & "')"

        'Response.Write("strSQL= " & strSQL & "<br>")

        '' Execute the SQL to INSERT new customer
        'objCmd2 = New OleDbCommand(strSQL, objDBConn)

        '' Post success message
        'strSuccess.Text = "<h2>Customer " & strPrice & " " & strCustList & " successfully added to database!</h2>"
        'strSuccess.Visible = "True"

        ' Close all objects

    End Sub
<title>Oracle Real Estate Sales</title>
<h1>Oracle Real Estate Sales</h1>
<asp:label id="strSuccess" runat="server" />
<form action="insert_customer_oracle.aspx" method="post" runat="server">
        <asp:TextBox ID="price" runat="server" Width="122px"></asp:TextBox></p>
        Contract ID:
        <asp:DropDownList ID="contractList" runat="server">
        </asp:DropDownList> </p>
        Home ID:
        <asp:DropDownList ID="homeList" runat="server">
        </asp:DropDownList> </p>
        <asp:TextBox ID="day" runat="server" Width="28px"></asp:TextBox>
        <asp:TextBox ID="month" runat="server" Width="37px"></asp:TextBox>
        <asp:TextBox ID="year" runat="server" Width="45px"></asp:TextBox></p>
        <asp:DropDownList ID="agentList" runat="server">
        </asp:DropDownList> </p>
        <asp:DropDownList ID="custList" runat="server">
        </asp:DropDownList> </p>
        <asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" />

Thread Tools
Display Modes

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 Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Specified cast is not valid heba ASP.NET 2.0 Professional 1 May 27th, 2007 09:51 PM
Specified cast is not valid. Jose P C# 5 May 11th, 2007 09:04 AM
Specified cast is not valid surajb Crystal Reports 0 January 12th, 2007 02:03 PM
Specified cast is not valid TheMole BOOK: ASP.NET Website Programming Problem-Design-Solution 9 November 1st, 2004 05:09 PM

All times are GMT -4. The time now is 09:12 PM.

Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.