Results 1 to 4 of 4

Thread: s

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Dec 2002
    Location
    London
    Posts
    678

    s

    What is wrong with this code please?
    The error is : "Line 1: Incorrect syntax near 'USP_StatusUnzipFile'."

    Thanks


    public void UnzipFile(string strFilename)
    {
    try
    {
    string strSQL = "USP_StatusUnzipFile";
    string strConn = objects.clsConnect.ConnectionStringLocal;

    SqlCommand oCmd;
    SqlConnection oCon;

    oCon = new SqlConnection(strConn);
    oCmd = new SqlCommand(strSQL, oCon);

    oCmd.Parameters.Add("@Filename", SqlDbType.VarChar, 1000);
    oCmd.Parameters["@Filename"].Value = strFilename;

    oCon.Open();
    oCmd.ExecuteNonQuery();
    oCon.Close();
    }

    catch (Exception ex)
    {
    throw ex;
    }

    }

  2. #2
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    Originally posted by fmardani
    What is wrong with this code please?
    The error is : "Line 1: Incorrect syntax near 'USP_StatusUnzipFile'."

    Thanks


    public void UnzipFile(string strFilename)
    {
    try
    {
    string strSQL = "USP_StatusUnzipFile";
    string strConn = objects.clsConnect.ConnectionStringLocal;

    SqlCommand oCmd;
    SqlConnection oCon;

    oCon = new SqlConnection(strConn);
    oCmd = new SqlCommand(strSQL, oCon);

    oCmd.Parameters.Add("@Filename", SqlDbType.VarChar, 1000);
    oCmd.Parameters["@Filename"].Value = strFilename;

    oCon.Open();
    oCmd.ExecuteNonQuery();
    oCon.Close();
    }

    catch (Exception ex)
    {
    throw ex;
    }

    }
    I can't see anything wrong with your code .

  3. #3
    PowerPoster hellswraith's Avatar
    Join Date
    Jul 2002
    Location
    Washington St.
    Posts
    2,464

    Re: s

    Originally posted by fmardani
    What is wrong with this code please?
    The error is : "Line 1: Incorrect syntax near 'USP_StatusUnzipFile'."

    Thanks


    public void UnzipFile(string strFilename)
    {
    try
    {
    string strSQL = "USP_StatusUnzipFile";
    string strConn = objects.clsConnect.ConnectionStringLocal;

    SqlCommand oCmd;
    SqlConnection oCon;

    oCon = new SqlConnection(strConn);
    oCmd = new SqlCommand(strSQL, oCon);

    oCmd.Parameters.Add("@Filename", SqlDbType.VarChar, 1000);
    oCmd.Parameters["@Filename"].Value = strFilename;

    oCon.Open();
    oCmd.ExecuteNonQuery();
    oCon.Close();
    }

    catch (Exception ex)
    {
    throw ex;
    }

    }
    Line 1 of what you showed us has nothing to do with that error text. Look at line 1 of the class or something.

  4. #4
    Hyperactive Member
    Join Date
    Aug 2002
    Location
    Fort Collins, CO
    Posts
    366
    That error is from the attempted execution of your stored proc. From the looks of your code it looks like that command object needs to know that you're trying to execute a stored proc and not just straight text. General rule of thumb on that exception handling, if you're not going to add anything to an exception you caught, then there's no reason to waste time catching it, just let it bubble up. I'd add a finally clause to ensure that the connection was closed though(Dispose does this on the connection object).

    here's your code with the addition of the finally clause and the appropriate commandtype:
    PHP Code:
    public void UnzipFile(string strFilename)
    {
        
    SqlCommand oCmd;
        
    SqlConnection oCon;
        try
        {
            
    string strSQL "USP_StatusUnzipFile";
            
    string strConn objects.clsConnect.ConnectionStringLocal;

            
    oCon = new SqlConnection(strConn);
            
    oCmd = new SqlCommand(strSQLoCon);

            
    oCmd.Parameters.Add("@Filename"SqlDbType.VarChar1000);
            
    oCmd.Parameters["@Filename"].Value strFilename
            
            
    oCmd.CommandType CommandType.StoredProcedure;
            
    oCon.Open();
            
    oCmd.ExecuteNonQuery();
            
    oCon.Close();
        }
        finally
        {
            if( 
    oCon != null )
            {
                
    oCon.Dispose();
            }
        }

    Here's an alternate way of doing the same thing:
    PHP Code:
    public void UnzipFile(string strFilename)
    {
        
    usingSqlConnection cn = new SqlConnectionobjects.clsConnect.ConnectionStringLocal ) )
        
    usingSqlCommand cmd = new SqlCommand"USP_StatusUnzipFile"cn ) )
        {
            
    cmd.CommandType CommandType.StoredProcedure;
            
    cmd.Parameters.Add"@Filename"strFilename );
            
    cmd.Connection.Open();
            
    cmd.ExecuteNonQuery();
        }


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width