C# - convert DeviceUniqueId (string) to int - windows-phone-8

I want to get a unique id in windows phone 8 .
I used DeviceUniqueId with the following code :
byte[] id = (byte[])Microsoft.Phone.Info.DeviceExtendedProperties.GetValue("DeviceUniqueId");
iden = BitConverter.ToString(id).Replace("-", string.Empty);
now I want to convert it to int
how can I do that ?

you have string iden, convert it to int like this:
int devId= Convert.ToInt32(iden);

Related

mysql convert string to int not working(with pdo)

I want to convert memberID from string to int first then do other operation in mysql but it seems that only num 3 sql work,how can i fix it?
otherwise,I have a question that why I input memberID by php int type but mysql insert it as string?
select hasGivePoint from posts where postID=:postID and json_search(hasGivePoint,'one',(convert(:memberID ,signed))) is not null;
update
posts
set
$pointName=$pointName-1,hasGivePoint=JSON_REMOVE(hasGivePoint,replace(json_search(hasGivePoint,'one',
convert(:memberID ,signed)),'\"',''))
WHERE postID=:postID;
";
update posts set $pointName=$pointName+1,hasGivePoint=JSON_ARRAY_APPEND(hasGivePoint,'$',convert(:memberID ,signed)) where postID=:postID;

Input string was not in a correct format with gridview update

I have this line of code
int Id = Convert.ToInt32(GridViewADMIN_Panel.DataKeys[e.RowIndex].Values[0]);
Getting "Input string was not in a correct format.
The error means that the value you are trying to cast is null or does not contain a valid integer. First you need to check if value is null and then caste value into int
if(GridViewADMIN_Panel.DataKeys[e.RowIndex].Values[0] != null)
{
//if value is not null then try to parse value into int
int Id = Int.TryParse(GridViewADMIN_Panel.DataKeys[e.RowIndex].Values[0]);
}
make sure, the value is int before you caste it.

SimpleJDBCCall handle out paramater with resultset

I am using spring jdbc. I want result set with out param. separately i done but together i am not able to do.
CREATE DEFINER=`xxx`#`%` PROCEDURE `client_xxxx`(
IN p_xxxx TINYINT(1) UNSIGNED,
IN p_result SMALLINT(2) UNSIGNED,
OUT p_result BIT ) BEGIN
IF EXISTS(SELECT 1 FROM xxx WHERE xxx = 1 AND xxx = 1) THEN
SELECT ...;
SET p_result = 0;
ELSE
SELECT ...;
SET p_result = 1;
END IF;
END
spring jdbc code
SimpleJdbcCall jdbcCall = new SimpleJdbcCall(dataSource).withProcedureName(sp);
List<Map<String, Object>> list = (List<Map<String, Object>>) jdbcCall.execute(paramsArray).get("#result-set-1");
list get the result set with result set how can i get p_result with that.
I find it in simple way that i miss.
public Map<String, Object> xxx(String sp, Object... paramsArray) {
SimpleJdbcCall jdbcCall = new SimpleJdbcCall(dataSource).withProcedureName(sp);
return jdbcCall.execute(paramsArray);
}
execute() gives two parameters default
i.e.
1) #result-set-1
2) #update-count-1
#result-set-1 result set i.e. select record
and #update-count-1 returns update count. If we want to access result with select statement with out parameter. we just have to declare out parameter. execute() gives all the things in Map<String, Object> type.
So from map we can get all the multiple values that stored procedure returns.
For example my SP like
PROCEDURE xxx(
IN xxxxTINYINT(1) UNSIGNED,
IN xxxSMALLINT(2) UNSIGNED,
OUT p_isconfig BIT
)
BEGIN
SELECT....
SET p_isconfig = 1;
END
So in #result-set-1 i get select result.
and p_isconfig gives me result to. If you have any confusion then you can iterate map and identify that how get return parameters.
Iterator i = map.keySet().iterator();
while ( i.hasNext() ) {
String key = (String) i.next();
String value = params.get( key );
System.out.println("key: " + key + " --- value: " + value) ;
}
This way i found solution after reading many things. If any one have other option for this solution then please share with me.
You can try morejdbc (available in maven central) to call your procedure, it's more laconic and it's type safe:
import static org.morejdbc.SqlTypes.BIGINT;
import static org.morejdbc.NamedJdbcCall.call;
import org.morejdbc.*;
...
private JdbcTemplate jdbcTemplate;
...
Out<Integer> out = Out.of(INTEGER);
jdbcTemplate.execute(call("client_xxxx")
.in("p_xxxx", pValue)
.out("p_result", out));
System.out.println("Result is " + out.get());
For ref_cursor out parameter and Oracle database you can use
Out<List<Record>> out = Out.of(OracleSqlTypes.cursor((rs, idx) -> new Record(rs)));
jdbcTemplate.execute(call("client_xxxx")
.in("p_xxxx", pValue)
.out("p_result", out)); // will auto-close ref-cursor
System.out.println("Got result records: " + out.get());

How to use DBNull.Value to check if table column is null; return default value if not null

My current while statement is being used to get all the values from a table (two integer and one string value) and it looks like this:
while (reader.Read())
{
Int16 a = reader.GetInt16("id");
**int b = (reader["nullable_id"] != DBNull.Value) ? Convert.ToInt16(reader["nullable_id"]): 0;**
string c = reader.GetString("string");
Site page = new Site(a, b, c);
list.Add(page);
}
What I am using it to do is to GET all the values in a table. There's a primary key, a foreign key, and a regular string value (a, b, and c respectively). This works fine as is by allowing me to pull the primary and the string value while ignoring the foreign key that currently has null values. However, if I were to alter one of the foreign keys's value to 32 from 'null', the value won't return when I execute the GET method.
So my question is, how do I check whether or not the foreign key is null or not and then, if it is not null, it returns the value stored in the database and if it is null, then it leaves the value as null? I'm relatively new with using DBNull so I may be implementing it incorrectly.
simple change use this
while (reader.Read())
{
Int16 a = Convert.ToInt16(reader["id"]);
int b = (!string.IsNullOrEmpty(Convert.ToString(reader["nullable_id"]))) ? Convert.ToInt16(reader["nullable_id"]): 0;
string c = Convert.ToString(reader["string"]);
Site page = new Site(a, b, c);
list.Add(page);
}

ORA-01465: invalid hex number while insert data from text area

i want insert data from jsp page to oracle database. i use textarea tag for write message.it s my contact form
here is my sql code
Create Table message(
id number primary key,
name varchar2(50),
student_id number,
mess varchar2(4000),
reply varchar2(4000));
and this is jsp code
String name = request.getParameter("name");
String mess = request.getParameter("mes");
String sid = (String) session.getAttribute("STID");
Class.forName("oracle.jdbc.driver.OracleDriver");
conn = DriverManager.getConnection("jdbc:oracle:thin:#localhost:1521:XE", "system", "12345");
ps = conn.prepareStatement("insert into message values(id_seq.nextval,?,?,?");
ps.setString(1, name);
ps.setString(2, sid);
ps.setString(3, mess);
when i click button i get ORA-01465: invalid hex number error. how can i resolve it?