Solved

Input string was not in a correct format

Posted on 2006-07-11
2
342 Views
Last Modified: 2011-09-20
Column or parameter #5: Cannot specify a column width on data type bit.
0
Comment
Question by:EPSCAT
2 Comments
 
LVL 142

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 500 total points
ID: 17087905
can you detail a bot more about what you have, like programming language or database type and version, a bit of the code etc.
Note that we are not sitting in front of your desk and don't have crystal ball either.
0
 

Author Comment

by:EPSCAT
ID: 17112738
The Programming Language is VB, The Database is MS SQL.

                        I'm having a problem(error's) implementing Custom Paging to a Editable Datagrid. I 've done tests and found the following results: The (Editable Datagrid that I'm using, uses some Template Columns) and works

fine by itself, and the (Custom Paging) works fine BUT ONLY if the Datagrid is not using Template Columns. I suspect something in the Custom Paging needs to be adjusted for it to work with the Template Columns???  

All of the files are posted below. If you have any question just ask... Thank You....



                  The Programming Laguage is VB, The database is MS SQL, The best way for you to see what I am doing is for me to post all 4 files. You will need to recreate the files on your computer just copy and paste. And also create a table named (Concertdates) on any database on your computer. And a stored procedure name (ConcertdatesSP) In the VB File on Line 30  change the (database name) to the one on your computer, and then just run the (DataGridCheckBox.aspx) This page should open up just fine. The Problem is when you click on the (FirstPage, PreviousPage, NextPage, LastPage) Link buttons is when I receive the error messages. They are all listed in the Error Messages.txt page. When creating the Concertdates (Table)You can look at the stored procedure for reference to see what column names to use for the (Concertdates) table creation. If you solve this for me. I will award you Points a Plenty!!!!! No Problem!!!!!!  

File # 1  ---(DataGridCheckBox.aspx)
File # 2  ---(2001010902.aspx.vb)
File #3   ---(ConcertDatesSP.sql)
File #4   ---(Error Messages.txt)



File # 1  ---(DataGridCheckBox.aspx)
________________________________________________________
<%@ Page Language="vb" Inherits="GridCustomPaging" Src="2001010902.aspx.vb" Debug="true" %>
<%@ import Namespace="System.Data" %>
<%@ import Namespace="System.Data.SQLClient" %>
<%@ import Namespace="System.Configuration" %>
<%@ import Namespace="System.Web.UI.WebControls" %>
<script runat="server">

    'Public Class DataGridCheckBox
    '  Inherits System.Web.UI.Page
   
    '  Protected dtgConcertDates As System.Web.UI.WebControls.DataGrid
       Public strSql As String
   
        Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
         If Not IsPostBack Then
           BindTheData()
         End If
       End Sub
   
        Sub BindTheData()
         Dim objConn As SqlConnection = New SqlConnection(ConfigurationSettings.AppSettings("ConnectionString"))
         strSql = "Select Top 10 UID, FullName, Title, ConcertDatesUrl, Discontinued From ConcertDates"
         Dim objCmd As SqlCommand = New SqlCommand(strSql, objConn)
   
         objConn.Open()
   
         dtgConcertDates.DataSource = objCmd.ExecuteReader(CommandBehavior.CloseConnection)
         dtgConcertDates.DataBind()
       End Sub
   
   
       Sub dtgConcertDates_Edit(sender As System.Object, e As DataGridCommandEventArgs)
         dtgConcertDates.EditItemIndex = e.Item.ItemIndex
         BindTheData()
       End Sub
   
       Sub dtgConcertDates_Cancel(sender As System.Object, e As DataGridCommandEventArgs)
         dtgConcertDates.EditItemIndex = -1
         BindTheData()
       End Sub
   
       Sub dtgConcertDates_Update(sender As System.Object, e As DataGridCommandEventArgs)
         Dim chkBoxChecked As Integer
         Dim UID As Integer
   
         UID = CType(e.Item.FindControl("lblUID"),Label).Text
         chkBoxChecked = (CType(e.Item.FindControl("edit_DiscontinuedCheckBox"),CheckBox).Checked) * -1
   
         strSql = "Update ConcertDates Set Discontinued=" & chkBoxChecked & " Where UID=" & UID
   
         Dim objConn As SqlConnection = New SqlConnection(ConfigurationSettings.AppSettings("ConnectionString"))
         Dim objCmd As SqlCommand = New SqlCommand(strSql, objConn)
   
         objConn.Open()
         objCmd.ExecuteNonQuery()
         objConn.Close()
         dtgConcertDates.EditItemIndex = -1
         BindTheData()
       End Sub
   
    'End Class

</script>
<html>
<head>
<style type="text/css" ref="stylesheet">
    .tableItem {font: x-small Verdana, Arial, sans-serif;}
   .tableHeader {font: bold small Arial; color:#663300; background-color:#CCCC66;}
   .alternatingItem {font: x-small Verdana, Arial, sans-serif; background-color:#FFFFCC;}
   A {color:#663300}
   A:hover {color:red}
   .pageLinks {font: bold x-small Verdana, Arial, sans-serif;}
</style>
    <title>DataGridCheckBox</title>
    <meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR" />
    <meta content="Visual Basic .NET 7.1" name="CODE_LANGUAGE" />
    <meta content="JavaScript" name="vs_defaultClientScript" />
    <meta content="http://schemas.microsoft.com/intellisense/ie5" name="vs_targetSchema" />
</head>
<body bgcolor="#0000c0" ms_positioning="GridLayout">
    <form id="form1" runat="server">
        <div align="center">
        </div>
        <div align="center">
        </div>
        <div align="center">
        </div>
        <div align="center">
        </div>
        <div align="center">
        </div>
        <div align="center">
        </div>
        <div align="center">
        </div>
        <div align="center">
        </div>
        <div align="center">
        </div>
        <div align="center">
        </div>
        <div align="center">
        </div>
        <div align="center">
            <table style="HEIGHT: 29px" height="150" width="1020" bgcolor="navy">
                <tbody>
                    <tr>
                        <td>
                            <p align="center">
                                <font face="Enviro" color="#ffff80"><a href="http://localhost/cdisland2/Webpages/intro.aspx"><font color="yellow">Main
                                Directory</font></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <a href="http://localhost/cdisland2/Webpages/Search/SearchByNameComplete.aspx"><font color="yellow">Search</font></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <a href="http://localhost/cdisland2/Webpages/Browse.aspx"><font color="yellow">Browse</font></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="yellow"> </font><a href="http://localhost/CDIslandCommerce/LoginGate.aspx"><font color="yellow">Login</font></a></font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <a href="Admin.aspx"><font face="Enviro" color="yellow">Home</font></a>&nbsp;&nbsp;&nbsp;&nbsp; <a href="Admin_InsertConcertDates1.aspx"><font face="Enviro" color="yellow">Insert
                                Calendar</font></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <a href="Admin_EditConcertDates.aspx"><font face="Enviro" color="yellow">Edit
                                Calendar</font></a>
                            </p>
                        </td>
                    </tr>
                </tbody>
            </table>
        </div>
        <div align="center">
        </div>
        <div align="center">
        </div>
        <div align="center">
            <asp:DataGrid id="dtgConcertDates" runat="server" PagerStyle-Visible="False" AllowCustomPaging="True" AllowPaging="True" AutoGenerateColumns="False" CellPadding="4" OnEditCommand="dtgConcertDates_Edit" OnCancelCommand="dtgConcertDates_Cancel" OnUpdateCommand="dtgConcertDates_Update" BorderColor="Teal" BorderStyle="Double" BorderWidth="2px">
                <HeaderStyle font-names="Enviro" font-bold="True" forecolor="Lime" backcolor="#0000C0"></HeaderStyle>
                <PagerStyle visible="False" nextpagetext="Next &amp;gt;" prevpagetext="&amp;lt; Prev" horizontalalign="Right"></PagerStyle>
                <AlternatingItemStyle forecolor="White" backcolor="Blue"></AlternatingItemStyle>
                <ItemStyle forecolor="White" backcolor="#0000C0"></ItemStyle>
                <Columns>
                    <asp:EditCommandColumn ButtonType="PushButton" UpdateText="Update" CancelText="Cancel" EditText="Edit">
                        <HeaderStyle width="50px"></HeaderStyle>
                    </asp:EditCommandColumn>
                    <asp:TemplateColumn HeaderText="UID">
                        <HeaderStyle width="100px"></HeaderStyle>
                        <ItemTemplate>
                            <asp:Label id="lbluID" text='<%# Container.DataItem("UID") %>' runat="server" />
                        </ItemTemplate>
                    </asp:TemplateColumn>
                    <asp:TemplateColumn HeaderText="FullName">
                        <HeaderStyle width="200px"></HeaderStyle>
                        <ItemTemplate>
                            <%# Container.DataItem("FullName") %>
                        </ItemTemplate>
                    </asp:TemplateColumn>
                    <asp:TemplateColumn HeaderText="Title">
                        <HeaderStyle width="200px"></HeaderStyle>
                        <ItemTemplate>
                            <%# Container.DataItem("Title") %>
                        </ItemTemplate>
                    </asp:TemplateColumn>
                    <asp:HyperLinkColumn Text="ConcertDatesUrl" DataNavigateUrlField="ConcertDatesUrl" DataNavigateUrlFormatString="http://localhost/SomeFolder/Somefolder/ConcertDates/{0}" DataTextField="ConcertDatesUrl" HeaderText="ConcertDatesUrl"></asp:HyperLinkColumn>
                    <asp:TemplateColumn HeaderText="Discontinued">
                        <HeaderStyle width="100px"></HeaderStyle>
                        <ItemTemplate>
                            <asp:CheckBox ID="DiscontinuedCheckBox" Enabled="False" Checked='<%# Databinder.Eval(Container.DataItem, "Discontinued") %>' runat="server" />
                        </ItemTemplate>
                        <EditItemTemplate>
                            <asp:CheckBox ID="edit_DiscontinuedCheckBox" Enabled="True" Checked='<%# Databinder.Eval(Container.DataItem, "Discontinued") %>' Runat="server" />
                        </EditItemTemplate>
                    </asp:TemplateColumn>
                </Columns>
            </asp:DataGrid>
        </div>
        <div align="center">
            <center>
                <p class="pageLinks">
                    <b>Page <asp:Label id="CurrentPage" runat="server" cssclass="pageLinks"></asp:Label>of <asp:Label id="TotalPages" runat="server" cssclass="pageLinks"></asp:Label></b>
                </p>
                <asp:LinkButton id="FirstPage" runat="server" Text="[First Page]" OnCommand="NavigationLink_Click" CommandName="First" CssClass="pageLinks"></asp:LinkButton>
                <asp:LinkButton id="PreviousPage" runat="server" Text="[Previous Page]" OnCommand="NavigationLink_Click" CommandName="Prev" CssClass="pageLinks"></asp:LinkButton>
                <asp:LinkButton id="NextPage" runat="server" Text="[Next Page]" OnCommand="NavigationLink_Click" CommandName="Next" CssClass="pageLinks"></asp:LinkButton>
                <asp:LinkButton id="LastPage" runat="server" Text="[Last Page]" OnCommand="NavigationLink_Click" CommandName="Last" CssClass="pageLinks"></asp:LinkButton>
            </center>
        </div>
        <div align="center">
        </div>
        <div align="center">
        </div>
        <p>
        </p>
        <p>
        </p>
        <p>
        </p>
        <p>
        </p>
        <p align="center">
            <table style="HEIGHT: 29px" height="150" width="1020" bgcolor="navy">
                <tbody>
                    <tr>
                        <td>
                            <p align="center">
                                <font face="Enviro" color="#ffff80"><a href="http://localhost/cdisland2/Webpages/intro.aspx"><font color="yellow">Main
                                Directory</font></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <a href="http://localhost/cdisland2/Webpages/Search/SearchByNameComplete.aspx"><font color="yellow">Search</font></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <a href="http://localhost/cdisland2/Webpages/Browse.aspx"><font color="yellow">Browse</font></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="yellow"> </font><a href="http://localhost/CDIslandCommerce/LoginGate.aspx"><font color="yellow">Login</font></a></font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <a href="Admin.aspx"><font face="Enviro" color="yellow">Home</font></a>&nbsp;&nbsp;&nbsp;&nbsp; <a href="Admin_InsertConcertDates1.aspx"><font face="Enviro" color="yellow">Insert
                                Calendar</font></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <a href="Admin_EditConcertDates.aspx"><font face="Enviro" color="yellow">Edit
                                Calendar</font></a>
                            </p>
                        </td>
                    </tr>
                </tbody>
            </table>
        </p>
        <p align="center">
        </p>
    </form>
</body>
</html>

END FILE #1
_________________________________________________________________________________________




File # 2  ---(2001010902.aspx.vb)
___________________________________________________________________________________________
Imports System
Imports System.Data
Imports System.Data.SqlClient
Imports System.Web
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Web.UI.HtmlControls

Public Class GridCustomPaging : Inherits System.Web.UI.Page

  Protected dtgConcertDates As System.Web.UI.WebControls.DataGrid
  Protected CurrentPage As System.Web.UI.WebControls.Label
  Protected TotalPages As System.Web.UI.WebControls.Label
  Protected NextPage As System.Web.UI.WebControls.LinkButton
  Protected PreviousPage As System.Web.UI.WebControls.LinkButton
  Protected FirstPage As System.Web.UI.WebControls.LinkButton
  Protected LastPage As System.Web.UI.WebControls.LinkButton

  Protected _currentPageNumber As Int32 = 1

  Public Sub Page_Load ( sender As Object, e As EventArgs )

    If Not Page.IsPostBack Then
      BindData()
    End If
  End Sub

  Public Sub BindData()

    Dim myConnection As SqlConnection = New SqlConnection( "server=localhost;database=myData;trusted_connection=true;" )
    Dim myCommand As SqlCommand = New SqlCommand ( "ConcertDatesSP", myConnection )

    With myCommand
        .CommandType = CommandType.StoredProcedure
        .Parameters.Add ( New SqlParameter ( "@CurrentPage", SqlDbType.Int ) ).Value = _currentPageNumber
        .Parameters.Add ( New SqlParameter ( "@PageSize", SqlDbType.Int ) ).Value = dtgConcertDates.PageSize
        .Parameters.Add ( New SqlParameter ("@TotalRecords", SqlDbType.Int ) ).Direction = ParameterDirection.Output
    End With

    Try
      myConnection.Open()
      dtgConcertDates.DataSource = myCommand.ExecuteReader()
      dtgConcertDates.DataBind()
    Finally
      myConnection.Close()
    End Try

    CurrentPage.Text = _currentPageNumber.ToString()

    Dim _totalPages As Double = 1
    If Not Page.IsPostBack Then
      Dim _totalRecords As Int32 = CType(myCommand.Parameters("@TotalRecords").Value, Int32)
      _totalPages = _totalRecords / dtgConcertDates.PageSize
      TotalPages.Text = ( System.Math.Ceiling ( _totalPages ) ).ToString()
    Else
      _totalPages = Double.Parse ( TotalPages.Text )
    End If

    If _currentPageNumber = 1 Then

      PreviousPage.Enabled = false

      If _totalPages > 1 Then
        NextPage.Enabled = true
      Else
        NextPage.Enabled = false
      End If

    Else

      PreviousPage.Enabled = true

      If _currentPageNumber = _totalPages Then
        NextPage.Enabled = false
      Else
        NextPage.Enabled = true
      End If

    End If

  End Sub

  Protected Sub NavigationLink_Click ( sender As Object, e As CommandEventArgs )

    Select Case e.CommandName

      Case "First"
        _currentPageNumber = 1

      Case "Last"
        _currentPageNumber = Int32.Parse ( TotalPages.Text )

      Case "Next"
        _currentPageNumber = Int32.Parse ( CurrentPage.Text ) + 1

      Case "Prev"
        _currentPageNumber = Int32.Parse ( CurrentPage.Text ) - 1

    End Select

    BindData()
  End Sub

End Class

END FILE #2
_________________________________________________________________________________________






File #3   ---(ConcertDatesSP.sql)
__________________________________________________________________________________________

CREATE PROCEDURE ConcertDatesSP

 @CurrentPage int,
 @PageSize int,
 @TotalRecords int output
AS
 --Create a temp table to hold the current page of data
 --Add and ID column to count the records
 CREATE TABLE #TempTable
 (
  UID int IDENTITY PRIMARY KEY,
  FUllName nvarchar(100),
  Title nvarchar (100),
  ConcertDatesUrl nvarchar (100),
  Discontinued bit (1)

 )
 --Fill the temp table with the Customers data
 INSERT INTO #TempTable
 (
    FullName,
    Title,
    ConcertDatesUrl,
    Discontinued

  )
 SELECT
    FullName,
    Title,
    ConcertDatesUrl,
    Discontinued

 FROM
    ConcertDates
 --Create variable to identify the first and last record that should be selected
 DECLARE @FirstRec int, @LastRec int
 SELECT @FirstRec = (@CurrentPage - 1) * @PageSize
 SELECT @LastRec = (@CurrentPage * @PageSize + 1)
 --Select one page of data based on the record numbers above
 SELECT
    FullName,
    Title,
    ConcertDatesUrl,
    Discontinued

 FROM
    #TempTable
 WHERE
    UID > @FirstRec
 AND
    UID < @LastRec
 --Return the total number of records available as an output parameter
 SELECT @TotalRecords = COUNT(*) FROM ConcertDates
GO


END FILE # 3

__________________________________________________________________________________________





File #4   ---(Error Messages.txt)
____________________________________________________________________________________________

/-----------------------------------------Error Messages-------------------------------------------/
FirstPage(Link)Pressed gives this error message:


        Column or parameter #5: Cannot specify a column width on data type bit.  <--Marked In Red//


Line 40:     Try
Line 41:       myConnection.Open()
Line 42:       dtgConcertDates.DataSource = myCommand.ExecuteReader()   <--Marked In Red//
Line 43:       dtgConcertDates.DataBind()
Line 44:     Finally
 

    Source File: C:\Inetpub\wwwroot\Email_For Sending Sample\2001010902.aspx.vb    Line: 42


/-------------------------------------------------------------------------------------------------/
PreviousPage(Link)Pressed gives this error message:


               Input string was not in a correct format. <--Marked In Red//


Line 95:
Line 96:       Case "Prev"
Line 97:         _currentPageNumber = Int32.Parse ( CurrentPage.Text ) - 1    <--Marked In Red//
Line 98:
Line 99:     End Select
 


    Source File: C:\Inetpub\wwwroot\Email_For Sending Sample\2001010902.aspx.vb    Line: 94



/-------------------------------------------------------------------------------------------------/
PreviousPage(Link)Pressed gives this error message:


                Input string was not in a correct format.    <--Marked In Red//



Line 92:
Line 93:       Case "Next"
Line 94:         _currentPageNumber = Int32.Parse ( CurrentPage.Text ) + 1     <--Marked In Red//
Line 95:
Line 96:       Case "Prev"
 

Source File: C:\Inetpub\wwwroot\Email_For Sending Sample\2001010902.aspx.vb    Line: 94

/-------------------------------------------------------------------------------------------------/
PreviousPage(Link)Pressed gives this error message:


                Input string was not in a correct format. <--Marked In Red//



Line 89:
Line 90:       Case "Last"
Line 91:         _currentPageNumber = Int32.Parse ( TotalPages.Text )   <--Marked In Red//
Line 92:
Line 93:       Case "Next"
 

Source File: C:\Inetpub\wwwroot\Email_For Sending Sample\2001010902.aspx.vb    Line: 91


/-------------------------------------------------------------------------------------------------/

END FILE # 4
______________________________________________________________________________________




 
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

I know it’s not a new topic to discuss and it has lots of online contents already available over the net. But Then I thought it would be useful to this site’s visitors and can have online repository on vim most commonly used commands. This post h…
Entering a date in Microsoft Access can be tricky. A typo can cause month and day to be shuffled, entering the day only causes an error, as does entering, say, day 31 in June. This article shows how an inputmask supported by code can help the user a…
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now