Ver Mensaje Individual
  #5 (permalink)  
Antiguo 14/03/2005, 10:14
Avatar de Sayra
Sayra
 
Fecha de Ingreso: diciembre-2004
Mensajes: 365
Antigüedad: 19 años, 6 meses
Puntos: 1
Hola chicos gracias por responderme
La cuestion es que estoy revisando un codijo que su funcion es dar mantenimiento a las base de datos, es decir consulta, agregar, editar y eliminar registros, y entonces cuando esta haciendo la consulta muestra todos los campos de la tabla que esta consultando
Y bueno se quiere que muestre los necesarios no todos
pero la funcion que hace el string de conecion es algo asiprivate bool CheckConnectionString
{
get
{
if(_connectionstring == null)
{
if(_configconnectionstring == null)
{
return false;
}
else
{
try
{
_connectionstring = (string) ConfigurationSettings.AppSettings[_configconnectionstring];
}
catch(Exception ex)
{
return false;
}
return (_connectionstring != null);
}
}
else
{ return true;}
}
}


void BindGrid()
{

columninfo = ColumnInfoFromViewState;
primarykey = PrimaryKeyFromViewState;
if(columninfo == null || primarykey == null)
{
SqlDataReader pk = GetPrimaryKeyReader();
int i = 0;
while(pk.Read())
{
primarykey = pk["COLUMN_NAME"].ToString();
PrimaryKeyFromViewState = primarykey;
if(i !=0)
{
pk.Close();
throw new Exception("Only single column primary keys are supported");
}
i++;
HasPK = true;
}
pk.Close();
if(HasPK)
{
columninfo = GetDataTable("sp_columns '" + _table + "'"); //SqlHelper.ExecuteDataset(_connectionstring, CommandType.StoredProcedure, "sp_columns", new SqlParameter("@table_name", _table)).Tables[0];
ColumnInfoFromViewState = columninfo;
}
}

if(HasPK)
{
try
{
dt = GetDataTable("Select * From " + _table);

BuildColumns();
if(AddingNew)
{
AddNewRow();
}
}
catch(SqlException ex)
{
AddError("SQLException Error: " + ex.Message);
throw;
}
catch(Exception ex)
{
AddError("Exception Error: " + ex.Message);
throw;
}
}
else
{
AddError("The table " + _table + " does not have a PrimaryKey Set");
}
}

private SqlDataReader GetPrimaryKeyReader()
{
if(_connectionstring != null && _table != null)
{
SqlCommand cmd = new SqlCommand("sp_pkeys '" + _table + "'", new SqlConnection(_connectionstring));
cmd.Connection.Open();
return cmd.ExecuteReader(CommandBehavior.CloseConnection) ;
}
else
{
throw new Exception("ConnectionString(or ConfigConnectionString) and/or Table value was not set");
}
}

private DataTable GetDataTable(string sql)
{
if(_connectionstring != null)
{
SqlCommand cmd = new SqlCommand(sql, new SqlConnection(_connectionstring));
SqlDataAdapter sda = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
sda.Fill(dt);
return dt;
}
else
{
throw new Exception("ConnectionString value was not set");
}
}

private DataSet GetDataSet(string sql)
{
if(_connectionstring != null)
{
SqlCommand cmd = new SqlCommand(sql, new SqlConnection(_connectionstring));
SqlDataAdapter sda = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
sda.Fill(ds);
return ds;
}
else
{
throw new Exception("ConnectionString value was not set");
}
}

Tu conoces el rainbow?
es un modulo que trae ella
se llama Database TAbleEdit

Y en cuanto a lo de hacer una vista, pues con mucha pena le digo que no se ni por donde empezar para hacer una

Gracias de antemano