C# 如何使用SqlCommand选择输入?(带铸造、倒圆和isnull)
我编写了这个SQL语句,并使用SQLServerManagementStudio进行了测试。但是,我不知道如何使用C#来实现这一点。我试过使用C# 如何使用SqlCommand选择输入?(带铸造、倒圆和isnull),c#,sql,sql-server-2008,C#,Sql,Sql Server 2008,我编写了这个SQL语句,并使用SQLServerManagementStudio进行了测试。但是,我不知道如何使用C#来实现这一点。我试过使用SqlCommand.ExecuteNonQuery()但它不起作用。我错过了什么 C#: 您需要在ExecuteNonQuery之前添加此行: connection.Open(); 因此,代码应该如下所示: connection = new SqlConnection(strConnect); //connection already defined
SqlCommand.ExecuteNonQuery()代码>但它不起作用。我错过了什么
C#:
您需要在ExecuteNonQuery
之前添加此行:
connection.Open();
因此,代码应该如下所示:
connection = new SqlConnection(strConnect); //connection already defined above
connection.Open();
SqlCommand command = new SqlCommand(query, connection);
command.ExecuteNonQuery();
如果仍然出现错误,请发布引发的特定异常和消息。HTH…出现了一个错误,您是否收到了一个错误?您是否在应用程序中使用与SSMS不同的凭据进行连接?你正在为你的应用使用的凭据,它是否有权访问你的第二个DB?更多信息=更多更好的帮助。我们不是通灵者=p可能你已经忘记打开连接..我的登录凭据对于两个数据库是相同的,但是我的连接字符串设置为db1@bonCodigo我之前已经检查过了,但是我想我会再看一眼这只在目标表还不存在的情况下才有效-这会是问题吗?如果目标表db2.dbo.CustomerTemp
已经存在-它将不起作用-即使在SQL Server Mgmt Studio中也不起作用
connection = new SqlConnection(strConnect); //connection already defined above
connection.Open();
SqlCommand command = new SqlCommand(query, connection);
command.ExecuteNonQuery();