Scusate la domandaccia fatta proprio da principiante...
ma come passo un valore fra due classi diverse?
io ho provato a derivare la classe nel modo solito ( class A : B) ma non funziona...
mi spiego meglio
ho due classi.
la prima dove definisco tutto ciò che occorre per conettermi ad un DB e caricarlo di dati...
la seconda dovrebbe essere usata per aggiornare i dati di una tabella...ma il valore del DataAdapter che ho assegnato nella prima e che dovrei recuperare per essere usato nella seconda non riesco a leggerlo....
codice:
using System;
using System.Data;
using System.Data.Common;
using System.Data.OleDb;
namespace TeaCon01
{
public class GestiBaDa : ConnDB
{
private string dbrecordset;
private string tsqlstringa;
public GestiBaDa()
{
// non usato
}
public string DBRecordset
{
get
{
return dbrecordset;
}
set
{
dbrecordset = value;
}
}
public string TSQLStringa
{
set
{
tsqlstringa = value;
}
}
public void InserisciDati(string [,] arrayElem, string nomeTabellaDB)
{
DataSet DSVisual = new DataSet();
DataTable DBTable = new DataTable();
this.tableNameDB = nomeTabellaDB;
DSVisual = Connessione();
DBTable = DSVisual.Tables[nomeTabellaDB];
DataRow DBRows;
DBRows = DBTable.NewRow();
try
{
DBRows["NomeIscritto"] = arrayElem[0,1];
DBRows["CognomeIscritto"] = arrayElem[1,1];
DBRows["IndirizzoIscritto"] = arrayElem[2,1];
DBRows["NCivicoIscritto"] = arrayElem[3,1];
DBRows["CAPIscritto"] = arrayElem[4,1];
DBRows["CittaIscritto"] = arrayElem[5,1];
DBRows["ProvIscritto"] = arrayElem[6,1];
}
catch
{
throw;
}
DBTable.Rows.Add(DBRows);
/////// QUI DOVREI RICHIMARE IL MIO DBAdapter CHE SI TROVA IN CONNDB()
}
// Seconda classe
public class ConnDB
{
private string tablenamedb;
public string tableNameDB
{
get
{
return tablenamedb;
}
set
{
tablenamedb = value;
}
}
public ConnDB()
{
}
public DataSet Connessione()
{
try
{
string DBConnString;
string sqlStringaDB = "SELECT * FROM ";
DBConnString = @"Provider=Microsoft.jet.oledb.4.0;data source=C:\Documents and Settings\myDir\Documenti\Visual Studio Projects\WindowsApplication4\TeCoDaBa\TeaConDB.mdb;Mode=ReadWrite|Share Deny None;Jet OLEDB:Engine Type=5";
OleDbConnection DBConnect = new OleDbConnection(DBConnString);
DBConnect.Open();
sqlStringaDB = sqlStringaDB + tablenamedb;
OleDbDataAdapter DBAdapter = new OleDbDataAdapter(sqlStringaDB, DBConnect);
DataSet DBSet = new DataSet(tablenamedb);
DBAdapter.FillSchema (DBSet, SchemaType.Source, tablenamedb);
DBAdapter.Fill (DBSet, tablenamedb);
return DBSet;
}
catch(Exception ex)
{
throw;
}
}
public void Disconnessione()
{
//DBConnect.Close();
}
}
}
queste sono le due classi...
grazie dell'aiuto