Ver Mensaje Individual
  #3 (permalink)  
Antiguo 06/04/2008, 10:47
miguebols
 
Fecha de Ingreso: marzo-2006
Mensajes: 18
Antigüedad: 18 años, 2 meses
Puntos: 1
Re: Listar tablas de una BBDD sp_tables

No lo consigo. Tengo 2 problemas:

1- Tal y como hago la conexion al servidor de BBDD (que se hace bien), como le especifico que el comando que voy a ejectuar es para una BBDD en particular???.
Porque he intentado conectarme directamente a la BBDD que quiero con la ruta que me pone el SQL Server (SQLEXPRESS\Databases\Languages) pero me da error.

2. El hacer DataSet.ToString() no me vale para imprimir las tablas,no? (aunque el comando que yo haya mandado sea un sp_tables)


Código:
        String server = DropDownList1.Items[DropDownList1.SelectedIndex].ToString();

        // Sets the conexion
        SqlConnection myConnection = new SqlConnection(
            "Server=" + server + "; " +
            "database=master; integrated security=yes");
        try
        {
            // Starts the conexion
            myConnection.Open();
            Label2.Text = "myConnection to DataBase Succesfully";
            // Create a command to execute
            SqlCommand myCommand = new SqlCommand("EXEC sp_tables", myConnection);
            myCommand.CommandType = CommandType.Text;
            // Create a SqlDataAdapter.
            SqlDataAdapter myAdapter = new SqlDataAdapter();
            myAdapter.SelectCommand = myCommand;
            // Create a DataSet.
            DataSet myDS = new DataSet();
            // Link myCommand to myAdapter.
            myAdapter.SelectCommand = myCommand;
            // Execute and read data
            myAdapter.Fill(myDS);
            Label3.Text = myDS.ToString();
        }