Creating a stored procedure via C#

前端 未结 4 744
情话喂你
情话喂你 2020-12-09 22:19

I\'m trying to create a seed DB in my web app, and i was able to create the DB, populate the tables, i\'m just stuck at getting the stored procedures to work. Here is what i

4条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-09 23:00

    Instead of using 'USE [DataBase] Go' you can set or change the current database for an open SqlConnection very easily:

    connection.ChangeDatabase("YourDB");
    

    An example:

    private static void ConctDatabase(string connectionString)
    {
        using (SqlConnection conn = new SqlConnection(connectionString))
        {
            conn.Open();
            MessageBox.Show("Database: {0}", conn.Database);
            conn.ChangeDatabase("Northwind");
            MessageBox.Show("Database: {0}", conn.Database);
        }
    }
    

提交回复
热议问题