locked
Prevent from collapsing the application RRS feed

  • Question

  • User-1024202203 posted

     I am importing the Excel sheet data into Textbox controls based Key Column(WONumber) from application folder where all Excel files resided.if i typed wrong WONumber(Un available file in Excefilesl folder) and clck on load application getting collpased, i wanted to prevent this and just through a message "WONumber is not presente in the Excelfile folder"

    Error message

    Server Error in '/JobTrack' Application.
    --------------------------------------------------------------------------------

    Syntax error (missing operator) in query expression 'Wono='.
    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.Data.OleDb.OleDbException: Syntax error (missing operator) in query expression 'Wono='.

    Following code is to Import excel data into Textbox controls.

     Try
                Dim strExcelConn As String = System.Configuration.ConfigurationManager.ConnectionStrings.Item("ExcelConnection").ToString()
                Dim dbConn As New OleDbConnection(strExcelConn)
                Dim db As OleDbDataReader
                Dim strSQL As String
                ' strSQL = "SELECT Custname,Part_no FROM [Shipment$] where Longlead=" & txtID.Text & ""
                strSQL = "SELECT * from [WO$] where Wono=" & txtWON.Text & ""
                dbConn.Open()
                Dim cmd As New OleDbCommand(strSQL, dbConn)
                Dim dsExcel As New DataSet
                Dim daExcel As New OleDbDataAdapter(cmd)
                daExcel.Fill(dsExcel)
                'GVStatus.DataSource = dsExcel
                'GVStatus.DataBind()
                db = cmd.ExecuteReader
                db.Read()
                txtWON.Text = db.Item(0).ToString
                txtPartNumber.Text = db.Item(1).ToString
                txtRev.Text = db.Item(2).ToString
                txtOQty.Text = db.Item(3).ToString
                txtCust.Text = db.Item(4).ToString
    
            Catch ex As Exception
                Throw ex
            End Try
    PLease help,thanks


     

     

     

    Sunday, January 30, 2011 9:21 PM

Answers

  • User-1171043462 posted

    Use required field validator

        <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
        <asp:RequiredFieldValidator ID="RequiredFieldValidator1" ControlToValidate = "TextBox1" runat="server" ErrorMessage="Required"></asp:RequiredFieldValidator>
    


     

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, January 31, 2011 1:37 AM

All replies

  • User-1171043462 posted

    The error occurs when your Textbox txtWON is empty

    Thus your query becomes SELECT * from [WO$] where Wono=

    which will give syntax error

    strSQL = "SELECT * from [WO$] where Wono=" & txtWON.Text & "" 

    Hence first check whether texbox has values by adding some validations

    Monday, January 31, 2011 12:01 AM
  • User-1024202203 posted

    Yes mudassar i wanted to check before going to search in Excel folder, can you please help how can i check 

    Monday, January 31, 2011 1:28 AM
  • User-1171043462 posted

    Use required field validator

        <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
        <asp:RequiredFieldValidator ID="RequiredFieldValidator1" ControlToValidate = "TextBox1" runat="server" ErrorMessage="Required"></asp:RequiredFieldValidator>
    


     

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, January 31, 2011 1:37 AM