MS Access Stored Procedure

  • Thread starter Thread starter Jim Heavey
  • Start date Start date
J

Jim Heavey

Hello, this is my first attempt of calling a Microsoft Access stored SQL
statement which expects a value to be passed to it. I think I am having
a problem generating the Parameter for running this procedure in my C#
application. I run the following SQL Statement in Access and it runs
just fine, it prompts me for a value, I supply it and then it brings
back the results, if any.

SELECT Skater.LastName+', '+Skater.FirstName+' '+Skater.LastName AS
['SkaterName'], USFSA_ID
FROM Skater
WHERE LastName Like [Enter the First Character of Last Name:]+'*'
ORDER BY Skater.LastName;


Nothing particularly difficult.

To call this SQL statment in my C# application, I do the following:

OleDbConnection cn = new OleDbConnection(_cnStr);
cn.Open();
OleDbCommand cmd = new OleDbCommand("QuerySkaterByLastName", cn);
cmd.CommandType = CommandType.StoredProcedure;
OleDbParameter parm = new OleDbParameter("LstNameChar",lastNameChar);
parm.Direction= ParameterDirection.Input;
parm.DbType = DbType.String;
cmd.Parameters.Add(parm);
OleDbDataReader rdr = cmd.ExecuteReader();
while (rdr.Read())
{
ListItem item = new ListItem(rdr[0].ToString()); //SkaterName
item.Value = rdr[1].ToString(); //USFSA_ID
drpLastNames.Items.Add(item);
}
rdr.Close();

Every time I run this procedure it runs without error, but never returns
any records. I watch it in debug mode and when it hits the "While
(rdr.Read()), it goes immediately to the close.

There is data which meets this criteria, but it fails to find it. I can
only summize that I have somehow set the parameter up incorrectly.

Any ideas as to what I am doing wrong?
 
Back
Top