ExecuteReader via OleDB ne marche pas pour une certaine requête
Bonjour à tous,
Je suis en train de développer une page web en ASP.NET/C#.
Pour résumer, j'ai un tableau listant un ensemble de fiches (le tableau est rempli en source de données via une base .accdb), après deux possibilités: créer ou modifier une fiche. Ayant fini la création avec l'envoi dans la base, je planche sur la modif.
Afin de remplir toutes les "Textbox" et autres champs, voilà sur quoi je suis parti:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
|
oConnection = new OleDbConnection();
sConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\\Users\\[...].accdb;Persist Security Info=True";
oConnection.ConnectionString = sConnectionString;
// Ouverture
[...]
// Requête
string sql = "SELECT NUMERO FROM matable1 WHERE CODE = '" + code + "'";
try
{
OleDbCommand oledb_Command = new OleDbCommand(sql);
oledb_Command.Connection = oConnection;
oledb_Command.CommandText = sql;
OleDbDataReader dr = oledb_Command.ExecuteReader();
while (dr.Read())
{
TextBox_blabla.Text = dr["NUMERO"].ToString();
}
}
catch(Exception ex)
{
Response.Write("<script>alert('Sql failure')</script>");
Label_error.Text = ex.ToString();
}
// Fermeture
[...] |
Et voilà l'erreur retournée:
Citation:
System.Data.OleDb.OleDbException: Type de données incompatible dans l'expression du critère. à System.Data.OleDb.OleDbCommand.ExecuteCommandTextErrorHandling(OleDbHResult hr) à System.Data.OleDb.OleDbCommand.ExecuteCommandTextForSingleResult(tagDBPARAMS dbParams, Object& executeResult) à System.Data.OleDb.OleDbCommand.ExecuteCommandText(Object& executeResult) à System.Data.OleDb.OleDbCommand.ExecuteCommand(CommandBehavior behavior, Object& executeResult) à System.Data.OleDb.OleDbCommand.ExecuteReaderInternal(CommandBehavior behavior, String method) à System.Data.OleDb.OleDbCommand.ExecuteReader(CommandBehavior behavior) à System.Data.OleDb.OleDbCommand.ExecuteReader() à _Default.populateFieldsFromDB() dans c:\Users\Geoff\Documents\Visual Studio 2008\WebSites\CLEOR\Fiche_Integration_Modif.aspx.cs:ligne 83
Mais le plus intrigant et ce que je ne comprend pas, c'est que j'utilise cette méthode pour remplir un champs dans un formulaire et que ça marche...
voilà pour info:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
|
oConnection = new OleDbConnection();
sConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\\Users\\Geoff\\Desktop\\CLEOR.accdb;Persist Security Info=True";
oConnection.ConnectionString = sConnectionString;
// Ouverture
[...]
// Requête
string sql = "SELECT MAGASIN FROM matable2 WHERE CODE = '" + code + "'";
try
{
OleDbCommand oledb_Command = new OleDbCommand(sql);
oledb_Command.Connection = oConnection;
oledb_Command.CommandText = sql;
OleDbDataReader dr = oledb_Command.ExecuteReader();
while (dr.Read())
{
TextBox_identification_magasin.Text = dr["MAGASIN"].ToString();
}
}
catch
{
Response.Write("<script>alert('Sql failure')</script>");
}
// Fermeture
[...]
} |
Merci d'avance si vous pensez savoir ce qui pourrait ce passer!
Cordialement