Non riesco a salvare in una stringa il contenuto di un campo in una tabella.
Esaminate questo codice:
<script language=C# runat=server>
void Page_Load(Object sender, EventArgs e)
{
String ConnString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" +
Server.MapPath("autori.mdb");
OleDbConnection cn = new OleDbConnection(ConnString);
cn.Open();
string sql="select * from tblOpere where opera='Persiani'";
OleDbCommand cmd = new OleDbCommand(sql, cn);
OleDbDataReader rdr = cmd.ExecuteReader();
rdr.Read();
string dato=rdr["opera"];
}
</script>
Come si può notare ho cercato di estrapolare il contenuto del campo opera di un database nella stringa dato ma mi viene generato il seguente errore:
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.
Compiler Error Message: CS0029: Cannot implicitly convert type 'object' to 'string'
Line 27: string n=rdr["opera"];
Dove sta l'errore?