Error while running asp.net

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • sha2kk3@gmail.com

    Error while running asp.net


    While running this code "Invalid token 'try' in class, struct, or
    interface member declaration" error is comming. Please advice me......
    I am new to asp.net.

    try
    {
    string connString = "Server=server0 4;Database=Nort hwind;Integrate d
    Security=SSPI";
    string sql = "SELECT * FROM EmployeeDetails ";

    SqlConnection conn = new SqlConnection( connString );
    SqlCommand command = new SqlCommand( sql, conn );

    conn.Open();
    SqlDataReader reader = command.Execute Reader();
    this.dgEmployee details.DataSou rce = reader;
    conn.Close();
    // this.dgEmployee details.DataBin d();
    }
    catch ( Exception ex )
    {
    MessageBox.Show (ex.Message);
    }
    finally
    {
    conn.Close();
    }

  • Ignacio Machin \( .NET/ C# MVP \)

    #2
    Re: Error while running asp.net

    Hi,

    You have to place this code inside a method, apparently you have it below
    the class definition


    --
    Ignacio Machin,
    ignacio.machin AT dot.state.fl.us
    Florida Department Of Transportation


    <sha2kk3@gmail. com> wrote in message
    news:1142578663 .929380.295530@ e56g2000cwe.goo glegroups.com.. .[color=blue]
    >
    > While running this code "Invalid token 'try' in class, struct, or
    > interface member declaration" error is comming. Please advice me......
    > I am new to asp.net.
    >
    > try
    > {
    > string connString = "Server=server0 4;Database=Nort hwind;Integrate d
    > Security=SSPI";
    > string sql = "SELECT * FROM EmployeeDetails ";
    >
    > SqlConnection conn = new SqlConnection( connString );
    > SqlCommand command = new SqlCommand( sql, conn );
    >
    > conn.Open();
    > SqlDataReader reader = command.Execute Reader();
    > this.dgEmployee details.DataSou rce = reader;
    > conn.Close();
    > // this.dgEmployee details.DataBin d();
    > }
    > catch ( Exception ex )
    > {
    > MessageBox.Show (ex.Message);
    > }
    > finally
    > {
    > conn.Close();
    > }
    >[/color]


    Comment

    • yogeshprabhu

      #3
      RE: Error while running asp.net

      Ignacio is right, you need to place this code inside a method. For ASP.NET
      you would normally load page in Page_Load event. But your code under catch
      block will not work because MessageBox is a Windows Forms class not available
      under ASP.NET. I would follow some ASP.NET quickstart tutorials available on
      gotdotnet. Here's the link: http://samples.gotdotnet.com/quickstart/aspplus/

      Comment

      • noblespirit.an

        #4
        Re: Error while running asp.net

        string connString = "Server=server0 4;Database=Nort hwind;Integrate d
        Security=SSPI";
        string sql = "SELECT * FROM EmployeeDetails ";

        SqlConnection conn = new SqlConnection( connString );
        try
        {

        SqlCommand command = new SqlCommand( sql, conn );

        conn.Open();
        SqlDataReader reader = command.Execute Reader();
        this.dgEmployee details.DataSou rce = reader;
        conn.Close();
        //
        this.dgEmployee details.DataBin d();
        }
        catch ( Exception ex )
        {
        MessageBox.Show (ex.Message);
        }
        finally
        {
        conn.Close();
        }

        Comment

        Working...