OleDBException using Fill method of OleDbDataAdapter

I'm using a OleDbDataAdapter object to fetch certain data from a database and place it in a data set object. The code for this is presented below:

oleConn = new OleDbConnection(WebConfigurationManager.ConnectionStrings["PTDB-ConnectString"].ConnectionString);
oleComm = new OleDbCommand("spGetPartRevisionFromSN @SerialNumber = " + SN, oleConn);
oleComm.CommandType = CommandType.Text;
ds = new DataSet();
da = new OleDbDataAdapter(oleComm);
da.Fill(ds); //<--OleDbException occurs here

My problem is that when the program reaches the Fill method of the data adapter, I receive an OleDbException with the error being "Incorrect syntax near 'SN' ", where SN is an alphanumeric serial number. I have a few SNs that I'm testing, the pattern I notice is that the method seems to run fine with an SN that begins with a letter, e.g. "J123456", but this exception gets thrown for every SN that begins with a number, e.g. "1ABCDEF". I'm not alterting the SNs, which are just strings, in any way and I've run the SELECT query, defined in the stored procedure, in SQL Server Management Studio with both kinds of SNs without a problem. Is there something I'm missing?


Try this: oleComm = new OleDbCommand("spGetPartRevisionFromSN @SerialNumber = '" + SN.tostring + "'", oleConn);

String assignments and evaluations should be included in single quotes. I believe that @SerialNumber is a string.

Need Your Help

TCP disconnection if no data

networking tcp disconnect

I've checked out TCP protocol Wiki, but haven't found, if socket connection will time out if no data is transferred during the long period. I mean.. there will be no physical problems, but two comp...

Drop columns in Sybase ASE table

sql tsql sybase sybase-ase

How can I drop a column in a Sybase ASE 15 table setup.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.