如何在c#中执行多于1行的sql命令

Rag*_*ock 3 c# sql

我想知道如何一次执行多个 SQL 命令。

此刻我正在这样做:

using (SqlConnection sqlConnection1 = new SqlConnection(connectionString))
{
    using (SqlCommand cmd = new SqlCommand())
    {
        cmd.CommandText = "SELECT nome FROM teste";
        cmd.CommandType = CommandType.Text;
        cmd.Connection = sqlConnection1;

        sqlConnection1.Open();

        // execute the command
        SqlDataReader rdr = cmd.ExecuteReader();
        while (rdr.Read())
        {
            listBox1.Items.Add(rdr["name"].ToString()); 
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

但是我该怎么做才能执行

use [databaseX]
SELECT nome FROM teste
Run Code Online (Sandbox Code Playgroud)

在我的 C# 程序中?

Jon*_*ood 5

用分号 ( ;)分隔多个语句。

(顺便说一句,use通常不需要该语句,因为它已在您的连接字符串中设置。)