Hola gente! Estoy trabajando en un website de .net en c#, y me da el siguiente error:
System.Data.OleDb.OleDbException was unhandled by user code
Message="No coinciden los tipos de datos en la expresión de criterios."
Source="Microsoft JET Database Engine"
ErrorCode=-2147217913
StackTrace:
at System.Data.OleDb.OleDbCommand.ExecuteCommandTextE rrorHandling(OleDbHResult hr)
at System.Data.OleDb.OleDbCommand.ExecuteCommandTextF orSingleResult(tagDBPARAMS dbParams, Object& executeResult)
at System.Data.OleDb.OleDbCommand.ExecuteCommandText( Object& executeResult)
at System.Data.OleDb.OleDbCommand.ExecuteCommand(Comm andBehavior behavior, Object& executeResult)
at System.Data.OleDb.OleDbCommand.ExecuteReaderIntern al(CommandBehavior behavior, String method)
at System.Data.OleDb.OleDbCommand.ExecuteReader(Comma ndBehavior behavior)
at System.Data.OleDb.OleDbCommand.ExecuteReader()
at Ficha.Page_Load(Object sender, EventArgs e) in c:\Inetpub\wwwroot\Optica\Ficha.aspx.cs:line 38
at System.Web.Util.CalliHelper.EventArgFunctionCaller (IntPtr fp, Object o, Object t, EventArgs e)
at System.Web.Util.CalliEventHandlerDelegateProxy.Cal lback(Object sender, EventArgs e)
at System.Web.UI.Control.OnLoad(EventArgs e)
at System.Web.UI.Control.LoadRecursive()
at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
El código que tengo es:
OleDbConnection con;
OleDbCommand com;
OleDbDataReader dr;
int codigo;
try
{
codigo = (int)Session["codigo"];
}
catch { };
con = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=C:\\Inetpub\\wwwroot\\Optica\\App_Data\\bdo ptica.mdb");
com = con.CreateCommand();
com.CommandText = "select * from Clientes where codigo = '" + codigo + "'";
con.Open();
dr = com.ExecuteReader();
dr.Read();
TextBox1.Text = dr ["nombre"].ToString();
La base de datos Clientes contiene una serie de campos, de los cuales el campo codigo es entero y el resto de los campos son cadenas.
El error me da en la sentencia de dr = com.ExecuteReader(); ¿Alguien sabría decirme qué está mal?
Muchas Gracias!