我正在使用脚本任务从 sql 查询生成 json 文件。
脚本任务中的c#代码:
public void Main()
{
// TODO: Add your code here
ConnectionManager cm;
string sqlString = "";
System.IO.StreamWriter file = new System.IO.StreamWriter(@"f:\JSONOutput.txt");
sqlString = "SELECT * FROM[dbo].[JJVCACUProductElectron] where id in (1,2,3) for json auto";
System.Data.SqlClient.SqlConnection sqlConn;
System.Data.SqlClient.SqlCommand sqlComm;
cm = Dts.Connections["crm_vm_2017_cs_dotnet"];
sqlConn = (System.Data.SqlClient.SqlConnection)cm.AcquireConnection(Dts.Transaction);
sqlComm = new System.Data.SqlClient.SqlCommand(sqlString, sqlConn);
System.Data.SqlClient.SqlDataReader reader = sqlComm.ExecuteReader();
try
{
while (reader.Read())
{
file.WriteLine(reader[0]);
}
}
finally
{
// Always call Close when done reading.
reader.Close();
}
cm.ReleaseConnection(sqlConn);
Dts.TaskResult = (int)ScriptResults.Success;
}
生成的输出文件不完整,我猜某些列中可能有返回。如何删除输出中的返回字符?
MYYA
森林海
相关分类