I want to pass a list of Ids to a stored procedure using Simple.Data.
My stored procedure is...
CREATE TYPE IntValue AS TABLE (Value INT)
GO
CREATE PROCEDURE testTableSproc
#items IntValue READONLY
AS
SELECT * FROM #items
So far I've tried...
public class IntValue
{
public int Value { get; set; }
}
var db = Database.OpenNamedConnection("MyConnection")
var array = new int[] {1, 2, 3};
List<IntValue> results = db.testTableSproc(items: array);
also
List<IntValue> results = db.testTableSproc(
items: array.Select(x => new IntValue{ Value = x}).ToArray());
Any solutions or confirmation that this is not supported?
Figured it out - Simple.Data accepts DataTable as a type.
var db = ConnectionFactory.GetConnection();
var tbl = new DataTable("items");
tbl.Columns.Add("Value");
var row1 = tbl.NewRow();
row1["Value"] = 1;
tbl.Rows.Add(row1);
var row2 = tbl.NewRow();
row2["Value"] = 2;
tbl.Rows.Add(row2);
var row3 = tbl.NewRow();
row3["Value"] = 3;
tbl.Rows.Add(row3);
List<IntValue> results = db.testTableSproc(items: tbl);
The syntax for working with DataTables is quite clunky but it can be refactored out of sight.
Related
I'm doing KPI's in node-red, and I'm using node-red-node-firebird to connect my database and get the results from it. For that I made a query to select the columns I need, one of those is:
NAME Varchar(40), with an example value: "Pizzas"
(example: Select NAME from mytable)
When I receive the query response on node-red, I store it inside the msg.payload. The problem is the result that I get it isn't the string "Pizzas" but a buffer "NAME":{"type":"Buffer","data":[80,105,122,122,97,115]}}.
How can I get the string and not the buffer?
I already tried a lot of things, among them:
On the query I have tried cast(NAME AS varchar(40)) AS NAME; [NAME] without success. Put msg.payload.data.toString('utf-8') in function node but nothing happens, the function:
var objectData = msg.objectData; //this is the query response
//------------Columns----------------------------
var fields = [];
var i = 0;
if(objectData.length > 0) {
var data = objectData[0];
for(var key in data) {
fields[i] = key;
i++;
}
//TRY nº1
objectData.foreach(function(obj){
if (Buffer.isBuffer(obj) === true) {
obj = obj.toString('utf-8');
}
})
}
//-----------------------------------------
msg.method = "POST";
msg.url = //My api request//;
msg.headers = {};
msg.headers["Content-Type"] = "application/json";
msg.headers.Authorization = //auth//;
msg.payload = {
'groupID': 'Group123',
'companyID': 1221,
'table': 'DemoTable',
'fields': fields,
'data': objectData, //problem
'delete': true,
};
//TRY nº2
msg.payload = msg.payload.data.toString('utf-8');
return msg;
I solved my problem changing the select to:
SELECT cast(name as varchar(100) character set win1252) NOME FROM mytable
Thanks for the help :)
I have a sheet that shows Items Cost. What I want to do instead of showing numbers i want to use the following BLACKHORSE were B = 1, L = 2, A = 3,C=4,K=5,H=6,7=O,8=R,9=S and E=0. How do i put this in a script in Google Sheets to where say cell h9 the sum of the total cost of the items it puts the letters instead of numbers
There may be many ways to calculate the values that you want. Consider this as one approach.
function so5715442701() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheetname = "57154427";
var sheet = ss.getSheetByName(sheetname);
// code to find the key for a given value in a javascript key:value array
Object.prototype.getKey = function(value){
for(var key in this){
if(this[key] == value){
return key;
}
}
return null;
};
// a key:value array for BLACKHORSE
var blackhorse = {
B : 1,
L : 2,
A : 3,
C : 4,
K : 5,
H : 6,
O : 7,
R : 8,
S : 9,
E : 0
};
// get the cost value from a cell
var costprice = sheet.getRange("C15").getValue();
// convert the number to a string
var cost = costprice.toString(); // convert to string
//Logger.log("DEBUG: cost = "+cost+", length = "+cost.length);
// set a variable to accumulate the results
var costtotal="";
// loop through the characters in the cost value
for (var i = 0; i < cost.length; i++) {
var letter = cost.charAt(i);
var costkey = blackhorse.getKey(letter);
var costtotal = costtotal+costkey
}
//Logger.log("DEBUG: cost = "+cost+", Blackhourse cost = "+costtotal);
sheet.getRange("D15").setValue(costtotal);
}
CREDIT
- How can I process each letter of text using Javascript?
- How to get a key in a JavaScript object by its value?
I manage a large email list for my gaming society. In column A, I have the e-mails, and in column B, I have the usernames. I populate column B with a formula that extracts the name of the user from their e-mail address, which is often in the firstname.lastname#email.com form. Column B therefore returns "Firstname" after I run the formula if the user's email is in the firstname.lastname#email.com format.
Sometimes, however, the emails have just the initial of the first name (f.lastname#email.com) and, in these case, I want to have Column B return the word 'Gamer' rather than, for example, the first letter of the user's email.
Here is the script I use at the moment, which current deletes all rows with four or more numbers:
function removeNumbers() {
var sheet = SpreadsheetApp.getActiveSheet();
var rows = sheet.getDataRange();
var numRows = rows.getNumRows();
var values = rows.getValues();
var rowsDeleted = 0;
for (var i = 0; i <= numRows - 1; i++) {
var row = values[i];
if (row[0].toLowerCase().indexOf("robot") > -1) {
sheet.deleteRow((parseInt(i)+1) - rowsDeleted);
rowsDeleted++;
}
On your shared spreadsheet, use this
function firstName() {
var sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet()
var lr=sheet.getLastRow()
var val = sheet.getRange(2,1,lr-1,2).getValues();//get the col A email addrs
var newVal=[]//new array for before fitst period
for (var i = 0; i <= val.length-1; i++) {
var str=val[i][0].split(".")//split email at period
var len=str[0].length // determine lenght of number string of first split
if(val[i][1]=="inactive"){
newVal.push(["inactive"])
continue
}
if(len<=1){//if 1 or less
def="Gamer"
newVal.push([def]) //put Gamer in new array
}
else{
newVal.push([toTitleCase(str[0])]) //keep first name
}}
sheet.getRange(2, 2, newVal.length, 1).setValues(newVal)//set new values in col B
}
function toTitleCase(str) {
return str.replace(/\w\S*/g, function (txt) {
return txt.charAt(0)
.toUpperCase() + txt.substr(1)
.toLowerCase();
});
}
This well also run on the active sheet.
An array of Image Url path:
["http://cdncms.fonts.net/hero-images/FEX_Hero_Thumb.png ","http://cdncms.fonts.net/hero-images/Wilma_Hero_Thumb.png "]
asp.net mvc Controller :
public ActionResult Extract(string[] name)
{
//List<string> myList = name.ToList<string>();
for(int x = 0; x < name.Length; x++)
{
//string something = name[x];
var item = name[x];
Session["values"] = item;
}
char[] delimiter1 = new char[] { ',' }; // <-- Split on these
string[] array1 = Session["values"].ToString().Split(delimiter1, StringSplitOptions.RemoveEmptyEntries);
foreach (var item in array1)
{
string exts = Path.GetExtension(item); //illegal character
string strRealname = Path.GetFileName(item); illegal character
}
I know this problem due to the presence of [ character at the beginning and last .I have tried but not succeeded .Any idea how to remove this using split function in C#
Assuming that you have correctly identified the problem, you could do this before making it an array:
var values = Session["values"].ToString();
if(values.StartsWith("[")) values = values.Substring(1);
if(values.EndsWith("]")) values = values.Substring(0, values.Length - 1);
I'm trying to display IEnumerable int values in JQGrid. As seen below column gmu is IEnumerable int but does not show correctly in the grid. Instead of the values, this is what shows in the grid for that gmu column:
System.Linq.Enumerable+WhereSelectEnumerableIterator2[<>f__AnonymousType25[System.Int32,System.String,System.Int32,System.Int32,System.Int32],System.Int32]
var result = from x in test
group x by new { x.dau, x.population_estimate, x.year } into p
select new
{
dau = p.Key.dau,
population_estimate = p.Key.population_estimate,
year = p.Key.year,
gmu = p.Select(x => x.gmu)
};
int pageIndex = Convert.ToInt32(page) - 1;
int pageSize = rows;
int totalRecords = results.Count();
int totalPages = (int)Math.Ceiling((float)totalRecords / (float)pageSize);
var pageResults = result.Skip(pageIndex * pageSize).Take(pageSize);
var jsonData = new
{
total = totalPages,
page,
records = totalRecords,
rows = (
from pageResult in pageResults
select new
{
//id = pageResult.id,
cell = new[] {
pageResult.year.ToString(),
pageResult.dau.ToString(),
pageResult.gmu.ToString(),
pageResult.population_estimate.ToString(),
}
}).ToArray()
};
You just need to add "ToArray()" after "Select" in your Linq statement.
gmu = String.Join<int>(", ", p.Select(x => x.gmu))
What's happening is that, when it goes to render your IEnumerable object, .NET is implicitly invoking the "ToString()" function (it's not smart enough to actually enumerate the object on its own initiative), resulting in what you see.