Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Visual Basic > VB.NET 1.0 > VB.NET 2002/2003 Basics
| Search | Today's Posts | Mark Forums Read
VB.NET 2002/2003 Basics For coders who are new to Visual Basic, working in .NET versions 2002 or 2003 (1.0 and 1.1).
Welcome to the p2p.wrox.com Forums.

You are currently viewing the VB.NET 2002/2003 Basics 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 November 10th, 2006, 05:01 AM
Registered User
Join Date: Nov 2006
Location: , , .
Posts: 2
Thanks: 0
Thanked 1 Time in 1 Post
Default (VB.net): Input string was not in a correct format

(vb.net 1.1 -- sql server) i'm using following insert code. It is working fine when all the fields are filled but it is gives error when fields which allows null values are not filled...... i'm getting following errorVB.net): Input string was not in a correct format. plz suggest something, i'll be really thkful.

            myConn = New SqlConnection(ConfigurationSettings.AppSettings("S qlConnection.ConnectionString"))

            myComm = New SqlCommand("Add_BookDetails", myConn)
            myComm.CommandType = CommandType.StoredProcedure

            Dim ins As SqlParameterCollection
            ins = myComm.Parameters

            Dim status As String
            status = 1

            ins.Add("@BookID", SqlDbType.Int).Value = txtBookID.Text 'null allowed
            ins.Add("@Status", SqlDbType.Int).Value = status
            ins.Add("@Category", SqlDbType.VarChar).Value = txtBookCategory.Text
            ins.Add("@Title", SqlDbType.VarChar).Value = txtBookTitle.Text
            ins.Add("@Author", SqlDbType.VarChar).Value = txtAuthorName.Text 'null allowed
            ins.Add("@Description", SqlDbType.VarChar).Value = txtDescription.Text 'null allowed
            ins.Add("@ISBN_No", SqlDbType.VarChar).Value = txtISBN.Text 'null allowed
            ins.Add("@Price", SqlDbType.Float).Value = txtBookPrice.Text 'null allowed
            ins.Add("@PurchaseDate", SqlDbType.DateTime).Value = txtDate.Text 'null allowed
            ins.Add("@PublisherName", SqlDbType.VarChar).Value = txtPublisherName.Text 'null allowed


        Catch ex As Exception
        End Try

        Context.Items("Message1") = "Book added successfully."


Old November 10th, 2006, 11:18 AM
Friend of Wrox
Join Date: May 2006
Location: San Diego, CA, USA.
Posts: 643
Thanks: 0
Thanked 0 Times in 0 Posts

If you intend to put null into fields when there is no valid value entered by the user, you will want to set that parameter to dbnull. The cleanest way to do this might be to write a function that checks that the string or date (or whatever) is entered, and returns the value when it does, and dbnull when it doesn't

Woody Z http://www.learntoprogramnow.com

Similar Threads
Thread Thread Starter Forum Replies Last Post
Input string was not in a correct format. hertendreef ASP.NET 2.0 Professional 2 February 19th, 2008 06:22 PM
Input string was not in a correct format dgood9 ASP.NET 2.0 Professional 2 January 8th, 2007 01:26 PM
input string not in correct format sarah lee ASP.NET 1.0 and 1.1 Basics 10 October 30th, 2006 05:18 PM
Input string was not in a correct format. palleti VB.NET 2002/2003 Basics 2 October 17th, 2006 10:38 AM

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