我想知道如何一次执行多个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());
}
}
}
但是我该怎么办
use [databaseX]
SELECT nome FROM teste
在我的C#程序中?
最佳答案
用分号(;
)分隔多个语句。
(顺便说一句,通常不需要use
语句,因为它是在您的连接字符串中设置的。)