I am developing a registration page in BlackBerry app. I am sending all the fields entered to the local server.Country is one of the form fields and is in a ObjectChoiceField. Whenever user selects a country having more than one word for ex: United States of America, it says sign up failed. When user selects country with single name, registration is always successful.Can anybody guide me how can I make the ObjectChoiceField accept the spaces or remove the spaces in the country?
There is no problem in ObjectChoiceField. For example if you want to send the Value like "Black Berry" you must send it to the web service like "Black%20Berry". Because %20 takes the space character. So after you are taking the value form ObjectChoiceField means......
ar[obchfield.getSelectedIndex()];// this is your value say for example:"Black Berry".
Take this below code in seperate Classname Utility.java:
public class Utility {
public static String escapeHTML(String s){
StringBuffer sb = new StringBuffer();
int n = s.length();
for (int i = 0; i < n; i++) {
char c = s.charAt(i);
switch (c) {
case ' ': sb.append("%20"); break;
default: sb.append(c); break;
}
}
return sb.toString();
}}
Then do like this:
Utility.escapeHTML(ar[obchfield.getSelectedIndex()]);//converts the "Black Berry" to "Black%20Berry".
then it returns a String like: "Black%20Berry" and send it to server. Enough.
Your problem is solved.
If you have any doubt come on StackOverFlow chat room name "Life for Blackberry" to clarify Your and our doubts.
Related
I've been battling this for two days and am at a loss. I'm attempting to create node relationships and am severely failing.
Here is my code for creating and running the relationship.
var query = graphClient.Cypher
.Match("(apt_1:AttackPatterns)", "(apt_2:AttackPatterns)")
.Where((AttackPatterns apt_1) => apt_1.Id == Convert.ToInt64(apt.ID))
.AndWhere((AttackPatterns apt_2) => apt_2.Id == Convert.ToInt64(rt.Relationship_Target_ID))
.CreateUnique("(apt_1)-[:" + rtrn.ToString() + "]->(apt_2)");
query.ExecuteWithoutResults();
Here is the AttackPatterns class.
public class AttackPatterns
{
public long Id { get; set; }
public string Name { get; set; }
}
During runtime, the value for query equates, in one iteration, to the following:
MATCH (apt_1:AttackPatterns), (apt_2:AttackPatterns)\r\nWHERE (apt_1.Id = \"1\")\r\nAND (apt_2.Id = \"122\")\r\nCREATE UNIQUE (apt_1)-[:ChildOf]->(apt_2)
I notice the "\r\n" characters. I also notice quotes around 1 and 122. When I paste this into the Neo4j web interface replacing "\r\n" with actual new lines and remove the "\" escape character before the quotes, it fails. If I remove the quotes around the 1 and 122, it successfully creates the relationship.
I'm really not sure what I'm doing wrong and would appreciate any assistance!
I've made some assumptions about types, as I think I know what's going on - basically - the Convert.ToInt64 isn't called before the query is made, you have to do it outside of the query generation:
//Given:
var apt = new { ID = "1" };
//Convert outside query
var ap1Id = Convert.ToInt64(apt.ID);
//Use in query
var query = gc.Cypher
.Match("(apt_1:AttackPatterns)", "(apt_2:AttackPatterns)")
.Where((AttackPatterns apt_1) => apt_1.Id == ap1Id) // <-- using locally created var
/* etc */
The \r\n is just for formatting when you look at the DebugQueryText property, they're not sent across, the only problem is the " around the numbers.
Please feel free to add this as a bug to the github project and I'll have a look into it, ideally it would be executed beforehand, but it's possibly like this for a reason.
I have to create method for table in Dynamics AX which concatenate two fields from one table in one field. For example Name+Surname displays in one field. How can I do it?
Create display method like this:
public display PersonName fullName()
{
return this.FirstName + ' ' + this.LastName;
}
See also edit method.
To concatenate two fields (or more) you can use StrFmt() method.
Example:
str fullName;
fullName = strFmt("%1 %2", this.Name, this.Surname);
This query produces an error No value given for one or more required parameters:
using (var conn = new OleDbConnection("Provider=..."))
{
conn.Open();
var result = conn.Query(
"select code, name from mytable where id = ? order by name",
new { id = 1 });
}
If I change the query string to: ... where id = #id ..., I will get an error: Must declare the scalar variable "#id".
How do I construct the query string and how do I pass the parameter?
The following should work:
var result = conn.Query(
"select code, name from mytable where id = ?id? order by name",
new { id = 1 });
Important: see newer answer
In the current build, the answer to that would be "no", for two reasons:
the code attempts to filter unused parameters - and is currently removing all of them because it can't find anything like #id, :id or ?id in the sql
the code for adding values from types uses an arbitrary (well, ok: alphabetical) order for the parameters (because reflection does not make any guarantees about the order of members), making positional anonymous arguments unstable
The good news is that both of these are fixable
we can make the filtering behaviour conditional
we can detect the category of types that has a constructor that matches all the property names, and use the constructor argument positions to determine the synthetic order of the properties - anonymous types fall into this category
Making those changes to my local clone, the following now passes:
// see https://stackoverflow.com/q/18847510/23354
public void TestOleDbParameters()
{
using (var conn = new System.Data.OleDb.OleDbConnection(
Program.OleDbConnectionString))
{
var row = conn.Query("select Id = ?, Age = ?", new DynamicParameters(
new { foo = 12, bar = 23 } // these names DO NOT MATTER!!!
) { RemoveUnused = false } ).Single();
int age = row.Age;
int id = row.Id;
age.IsEqualTo(23);
id.IsEqualTo(12);
}
}
Note that I'm currently using DynamicParameters here to avoid adding even more overloads to Query / Query<T> - because this would need to be added to a considerable number of methods. Adding it to DynamicParameters solves it in one place.
I'm open to feedback before I push this - does that look usable to you?
Edit: with the addition of a funky smellsLikeOleDb (no, not a joke), we can now do this even more directly:
// see https://stackoverflow.com/q/18847510/23354
public void TestOleDbParameters()
{
using (var conn = new System.Data.OleDb.OleDbConnection(
Program.OleDbConnectionString))
{
var row = conn.Query("select Id = ?, Age = ?",
new { foo = 12, bar = 23 } // these names DO NOT MATTER!!!
).Single();
int age = row.Age;
int id = row.Id;
age.IsEqualTo(23);
id.IsEqualTo(12);
}
}
I've trialing use of Dapper within my software product which is using odbc connections (at the moment). However one day I intend to move away from odbc and use a different pattern for supporting different RDBMS products. However, my problem with solution implementation is 2 fold:
I want to write SQL code with parameters that conform to different back-ends, and so I want to be writing named parameters in my SQL now so that I don't have go back and re-do it later.
I don't want to rely on getting the order of my properties in line with my ?. This is bad. So my suggestion is to please add support for Named Parameters for odbc.
In the mean time I have hacked together a solution that allows me to do this with Dapper. Essentially I have a routine that replaces the named parameters with ? and also rebuilds the parameter object making sure the parameters are in the correct order.
However looking at the Dapper code, I can see that I've repeated some of what dapper is doing anyway, effectively it each parameter value is now visited once more than what would be necessary. This becomes more of an issue for bulk updates/inserts.
But at least it seems to work for me o.k...
I borrowed a bit of code from here to form part of my solution...
The ? for parameters was part of the solution for me, but it only works with integers, like ID. It still fails for strings because the parameter length isn't specifed.
OdbcException: ERROR [HY104] [Microsoft][ODBC Microsoft Access Driver]Invalid precision value
System.Data.Odbc. OdbcParameter.Bind(OdbcStatementHandle hstmt,
OdbcCommand command, short ordinal, CNativeBuffer parameterBuffer, bool allowReentrance)
System.Data.Odbc.OdbcParameterCollection.Bind(OdbcCommand command, CMDWrapper cmdWrapper, CNativeBuffer parameterBuffer)
System.Data.Odbc.OdbcCommand.ExecuteReaderObject(CommandBehavior behavior, string method, bool needReader, object[] methodArguments, SQL_API odbcApiMethod)
System.Data.Odbc.OdbcCommand.ExecuteReaderObject(CommandBehavior behavior, string method, bool needReader)
System.Data.Common.DbCommand.ExecuteDbDataReaderAsync(CommandBehavior behavior, CancellationToken cancellationToken)
Dapper.SqlMapper.QueryAsync(IDbConnection cnn, Type effectiveType, CommandDefinition command) in SqlMapper.Async.cs
WebAPI.DataAccess.CustomerRepository.GetByState(string state) in Repository.cs
var result = await conn.QueryAsync(sQuery, new { State = state });
WebAPI.Controllers.CustomerController.GetByState(string state) in CustomerController .cs
return await _customerRepo.GetByState(state);
For Dapper to pass string parameters to ODBC I had to specify the length.
var result = await conn.QueryAsync<Customer>(sQuery, new { State = new DbString { Value = state, IsFixedLength = true, Length = 4} });
I am fairly new to SharePoint development and as you may all know that it is very basic for one to know how to access fields in a choice column...
My problem:
I want to access the values of the Check Boxes from a Choice Column.
For Example:
I have a document library called Libe, this document library has a custom column with type Choice and has 4 checkboxes with the values:
Category 1
Category 2
Category 3
Category 4
How do I get the values like literally the text values of what is in the Check Box List: "Category 1", "Category 2" ... "Category 4".
Any ideas?
I can access the column fine and get the selected values, I just do not know how to get the values the user can choose from.
Answer
SPFieldMultiChoice Fld = (SPFieldMultiChoice)list.Fields["Column"];
List<string> fieldList = new List<string>();
foreach (string str in Fld.Choices)
{
fieldList.Add(str);
}
Above is the answer, I can't answer my own question until I have a 100 rep.
using (SPSite site = new SPSite("http://servername/"))
{
using (SPWeb web = site.OpenWeb())
{
SPList list = web.Lists["ListName"];
string values = list["yourColumn"] as string;
string[] choices = null;
if (values != null)
{
choices = values.Split(new string[] { ";#" }, StringSplitOptions.RemoveEmptyEntries);
}
}
}
You can try this code for getting choice field value from document library.
I have one table member_details with field "preferred_location" (varchar) that has comma separated values like "19,20,22" that come from a listbox selection ....
Now I also have another table city_master having field "city_id" (int) and "city_name" (varchar)...
Now I want to separate "preferred_location" (varchar) values and to add them in integer field of temp table so I can make an inner join between city_id(int) of the temp table and city_id(int) of city_master and then can get city name from city_name of city_master...
This is all stuff I need in MySQL - either a stored procedure or a function. I am using it with c#.net.
Frankly, this sounds like a bad design. If you need the integers values separately, then modify your database structure accordingly, and save the values separately to begin with.
I mean, you see where it leads to - because you stored the values as a list in a string, you have maneuvered yourself into a position where you need to unwind the values each time you want to join the tables.
That's like putting the horse behind the wagon.
If these integers are small, like 19,20,22 etc just use smaller 16 or 8 bit integers (as supported by your database) and it should not take much more space than a string (possibly even less).
Made up some mock up example, but this should work with LinqToMySql as well.
class user {
public string name {get;set;}
public int id {get;set;}
}
class member_detail {
public int user_id {get;set;}
public string prefered {get;set;}
}
class city_master{
public int code {get;set;}
public string name {get;set;}
}
void Main()
{
var users = new List<user>();
users.Add(new user(){name = "Mary",id = 1});
users.Add(new user(){name = "John",id=2});
var details = new List<member_detail>() ;
details.Add(new member_detail(){user_id=1,prefered="1,2,3"});
details.Add(new member_detail(){user_id=2,prefered="3,5"});
var cities = new List<city_master>();
cities.Add(new city_master(){code =1,name="Moscow"});
cities.Add(new city_master(){code =2,name="London"});
cities.Add(new city_master(){code =3,name="Paris"});
cities.Add(new city_master(){code =4,name="Rome"});
cities.Add(new city_master(){code =5,name="Madrid"});
users.Select(u=>new {u.name,cities=
details.Where(d=>d.user_id==u.id)
.SelectMany(d=>d.prefered.Split(','))
.Join(cities,c=>c,d=>d.code.ToString(),(a,b)=>new {b.name})}).Dump();
}
thanks for your suggestion but in my case it is better to store ids of preferred location cities as comma separated.
I have a procedure that makes a temporary table and then I can use inner join with city_master table to get city names.
Create Procedure parseAndStoreList(in thingId int, in i_list varchar (128),
out returnCode smallInt)
BEGIN
DECLARE v_loopIndex default 0;
DECLARE Exit Handler for SQLEXCEPTION
BEGIN
call saveAndLog(thingId, 'got exception parsing list');
set returnCode = -1;
END;
call dolog(concat_ws('got list:', i_list));
pase_loop: LOOP set v_loopIndex = v_loopIndex + 1;
call dolog(concat_wc(',', 'at loop iteration ', v_loopIndex);
LOOOP parse_loop;
set returnCode = 0;
END;