|
Thread: s
-
Jun 23rd, 2004, 10:40 AM
#1
Thread Starter
Fanatic Member
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;
}
}
-
Jun 23rd, 2004, 06:20 PM
#2
Sleep mode
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 .
-
Jun 24th, 2004, 12:56 PM
#3
PowerPoster
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.
-
Jun 24th, 2004, 08:50 PM
#4
Hyperactive Member
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(strSQL, oCon);
oCmd.Parameters.Add("@Filename", SqlDbType.VarChar, 1000);
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)
{
using( SqlConnection cn = new SqlConnection( objects.clsConnect.ConnectionStringLocal ) )
using( SqlCommand 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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|