Вопрос

I need to open a pre-existing Database in ASP.NET Web Form with C#. So far all I have managed to find, are tutorial's on how to make a new Database and Table's.

If anyone know's how to do this please let me know.

Thanks'

Это было полезно?

Решение

  1. Open a connection to the database. You will need the proper connection string. The place to go is ConnectionStrings.com.

    SqlConnection conn = new SqlConnection(yourConnectionString);

  2. Create a command

     string yourSQL = "SELECT FirstName FROM Employees";
    

    SqlCommand cmd = new SqlCommand(yourSQL, conn);

  3. Do something with it..

    • execute a DataReader
    • fill a table with a DataAdapter

That's the basic pattern.

Другие советы

Add a connection string to web.config and then Write the connection code.

The following is a good place to start for the conn string and the code: https://www.connectionstrings.com/sql-server-2012/

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top