Wrox Programmer Forums
Go Back   Wrox Programmer Forums > SQL Server > SQL Server 2000 > SQL Server 2000
| Search | Today's Posts | Mark Forums Read
SQL Server 2000 General discussion of Microsoft SQL Server -- for topics that don't fit in one of the more specific SQL Server forums. version 2000 only. There's a new forum for SQL Server 2005.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Server 2000 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 12th, 2005, 01:58 PM
Registered User
 
Join Date: Feb 2005
Location: , , .
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default Cast from string "" to type 'Double' is not

Hi,
  In the code below iam trying to make a binding controls with using

SQl server 2000
the error msg i get is

An unhandled exception of type 'System.InvalidCastException' occurred

in microsoft.visualbasic.dll

Additional information: Cast from string "" to type 'Double' is not

valid.

and the coursor indicate to this line in Private Sub ShowPosition()

  txtPrice.Text = FormatNumber(txtPrice.Text, 2, TriState.True)


Imports System.Data
Imports System.Data.OleDb
Imports System.DBNull

Public Class Form
    Inherits System.Windows.Forms.Form
    Dim objjConnection As OleDbConnection = New _
    OleDbConnection("Provider=SQLOLEDB.1;Integrated Security=SSPI;" & _
    "Initial Catalog=pubs;Data Source=HOMEPC;Workstation ID=HOMEPC;")
    Dim objjDataAdapter As OleDbDataAdapter
    Dim objjDataSet As DataSet
    Dim objjDataView As DataView
    Dim objjCurrencyManager As CurrencyManager


#Region " Windows Form Designer generated code "

    Public Sub New()
        MyBase.New()

        'This call is required by the Windows Form Designer.
        InitializeComponent()

        'Add any initialization after the InitializeComponent() call
        cmbField.Items.Add("Last Name ")
        cmbField.Items.Add("Firts Name")
        cmbField.Items.Add("Book Title")
        cmbField.Items.Add("Price")
        cmbField.SelectedIndex = 0
        FillDataSetView()
        BindFields()
        ShowPosition()

    End Sub

    'Form overrides dispose to clean up the component list.
    Protected Overloads Overrides Sub Dispose(ByVal disposing As

Boolean)
        objjCurrencyManager = Nothing
        objjDataView = Nothing
        objjDataSet = Nothing
        objjDataAdapter = Nothing
        objjConnection = Nothing
        If disposing Then
            If Not (components Is Nothing) Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub


 Private Sub FillDataSetView()
        objjDataView = Nothing
        objjDataSet = New DataSet
        objjConnection.Open()
        objjDataAdapter = New OleDbDataAdapter( _
        "SELECT authors.au_id,au_lname,au_fname, " & _
        "titles.title_id,title, price " & _
        "FROM authors " & _
        "JOIN titleauthor ON authors.au_id = titleauthor.au_id " & _
        "JOIN titles ON titleauthor.title_id = titles.title_id " & _
        "ORDER BY au_lname, au_fname ", objjConnection)

        objjDataAdapter.Fill(objjDataSet, "authors")
        objjDataView = New DataView(objjDataSet.Tables("authors"))
        objjCurrencyManager = _
        CType(Me.BindingContext(objjDataView), CurrencyManager)
        objjConnection.Close()
        objjDataSet = Nothing
    End Sub

    Private Sub BindFields()
        txtAuthorID.DataBindings.Clear()
        txtLastName.DataBindings.Clear()
        txtFirstName.DataBindings.Clear()
        txtTitleID.DataBindings.Clear()
        txtBookTitle.DataBindings.Clear()
        txtPrice.DataBindings.Clear()
        txtAuthorID.DataBindings.Add("Text", objjDataView, "au_id")
        txtLastName.DataBindings.Add("Text", objjDataView, "au_lname")
        txtFirstName.DataBindings.Add("Text", objjDataView, "au_fname")
        txtTitleID.DataBindings.Add("Text", objjDataView, "title_id")
        txtBookTitle.DataBindings.Add("Text", objjDataView, "title")
        txtPrice.DataBindings.Add("Text", objjDataView, "price")
        StatusBar1.Text = "Ready"

    End Sub

    Private Sub ShowPosition()
        txtPrice.Text = FormatNumber(txtPrice.Text, 2, TriState.True)
        txtRecordPosition.Text = objjCurrencyManager.Position + 1 & _
        " of " & objjCurrencyManager.Count

    End Sub

Private Sub btnMoveFirst_Click(ByVal sender As System.Object, ByVal e

As System.EventArgs) Handles btnMoveFirst.Click
        objjCurrencyManager.Position = 0
        ShowPosition()

    End Sub

    Private Sub btnMovePrevious_Click(ByVal sender As System.Object,

ByVal e As System.EventArgs) Handles btnMovePrevious.Click
        objjCurrencyManager.Position -= 1
        ShowPosition()

    End Sub

    Private Sub btnMoveNext_Click(ByVal sender As System.Object, ByVal

e As System.EventArgs) Handles btnMoveNext.Click
        objjCurrencyManager.Position += 1
        ShowPosition()

    End Sub

    Private Sub btnMoveLast_Click(ByVal sender As System.Object, ByVal

e As System.EventArgs) Handles btnMoveLast.Click
        objjCurrencyManager.Position = objjCurrencyManager.Count - 1

        ShowPosition()

    End Sub




 
Old February 18th, 2005, 01:44 AM
Authorized User
 
Join Date: Feb 2005
Location: Pune, Maharashtra, India.
Posts: 30
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Try out this...
txtPrice.Text = FormatNumber(txtPrice.Text.ToString(), 2, TriState.True)







Similar Threads
Thread Thread Starter Forum Replies Last Post
Cast from string 'OPEN' to type 'Double' is not va yasinirshad .NET Framework 1.x 1 August 12th, 2007 12:45 PM
Cast from string to type Double not valid mika27 ASP.NET 2.0 Basics 0 January 31st, 2007 05:52 AM
Cast from string "" to type 'Double' is not dounme ADO.NET 1 March 8th, 2005 01:31 PM
Cast from string "" to type 'Integer' is not valid h3x SQL Server ASP 1 January 30th, 2005 09:35 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.