我有一个执行sql server存储过程的php文件,并返回一个VARCHAR数据类型的OUTPUT值。如果输出值设置为整数,则表示正常。如果输出值设置为varchar,则返回空值。下面是我的php代码和sql server存储过程。请帮帮我哪里错了。谢谢
<button (click)="download()">export to excel</button>
和存储过程
download(){
var csvData = this.ConvertToCSV(yourdata);
var a = document.createElement("a");
a.setAttribute('style', 'display:none;');
document.body.appendChild(a);
var blob = new Blob([csvData], { type: 'text/csv' });
var url= window.URL.createObjectURL(blob);
a.href = url;
a.download = 'User_Results.csv';/* your file name*/
a.click();
return 'success';
}
答案 0 :(得分:0)
我不得不用数据类型VARCHAR的C#和SQL输出参数处理类似的问题。我发现在C#中声明参数时我需要提到它的大小
// The below will not return any value larger than the length of existing value in someInitialValue
var myOutParam = new SqlParameter("@calculatedParam", someInitialValue);
myOutParam.Direction = ParameterDirection.InputOutput;
con.ExecuteQuery(...);
// if for example myInitialValue was "A" and your returned "XYZ" from the procedure, your finalValue would only be "X"
var finalValue = myOutParam.Value;
解决此问题的正确方法是提供具有预期大小的参数声明
// The below declaration will return properly
var myOutParam = new SqlParameter("@calculatedParam", someInitialValue);
myOutParam.Direction = ParameterDirection.InputOutput;
myOutParam.Size=3;
con.ExecuteQuery(...);
// if for example myInitialValue was "A" and your returned "XYZ" from the procedure, your finalValue would only be "XYZ"
var finalValue = myOutParam.Value;
将其转换为您的PHP要求,它应该解决您的问题。