When C# app is ran, it POSTS a request to the PHP server, which wants to return an array. What's an easy way to load this array's contents into C# for using with there.
Hello!
I'm having trouble getting my head around sending multiple models to a view in mvc.
My problem is the following.
Using EF4 I have a table with attributes organised by category.
Couldn't post an image :-(
[Have a table called attributes (AttributeTitle, AttributeName, CategoryID) connected to a table called Category (CategoryTitle).]
What I want to do is be able to edit an attribute entity and have a dropdown of categories to choose from.
I tried to make a custom viewmodel
public class AttributeViewModel
{
public AttributeViewModel()
{
}
public Attribute Attribute { get; set; }
public IQueryable<Category> AllCategories { get; set; }
}
But it just ended up being a mess.
<div class="editor-field">
<%: Html.DropDownList("Category", new SelectList((IEnumerable)Model.AllCategories, "CategoryID", "CategoryName")) %>
</div>
I was getting it back to the controller...
[HttpPost]
public ActionResult Edit(int AttributeID, FormCollection formcollection)
{
var _attribute = ProfileDB.GetAttribute(AttributeID);
int _selcategory = Convert.ToInt32(formcollection["Category"]);
_attribute.CategoryID = (int)_selcategory;
try
{
UpdateModel(_attribute); (<---Error here)
ProfileDB.SaveChanges();
return RedirectToAction("Index");
}
catch (Exception e)
{
return View(_attribute);
}
}
I've debugged the code and my _attribute looks correct and _attribute.CategoryID = (int)_selcategory updates the model, but then I get the error.
Somewhere here I thought that there should be a cleaner way to do this, and that if I could only send two models to the view instead of having to make a custom viewmodel.
To sum it up:
I want to edit my attribute and have a dropdown of all of the available categories.
Any help much appreciated!
I need to pull 3 values from a table and assign each one to a variable
each value is based on to columns, a type and an id
$ht_live_query = mysql_query("SELECT htcode FROM coupon WHERE pid='$pid' AND type='L'");
$ht_live_result = mysql_fetch_array($ht_live_query);
$htCODE_Live = $ht_live_result['htcode'];
You can see that I am assigning the desired value to the variable $htL
$ht_General_query = mysql_query("SELECT htcode FROM coupon WHERE pid='$pid' AND type='G'");
$ht_General_result = mysql_fetch_array($ht_General_query);
$htCODE_General = $ht_General_result['htcode'];
$ht_Reward_query = mysql_query("SELECT htcode FROM coupon WHERE pid='$pid' AND type='R'");
$ht_Reward_result = mysql_fetch_array($ht_Reward_query);
$htCODE_Reward = $ht_Reward_result ['htcode'];
I know I am doing this the hard way but can not figure out how to do the foreach or while loop to attain the desired results.
This one has bugged me for the longest time and a great question to ask the Stackoverflow users I think.
I have a rather large SSIS flow that uses a string variable to store the datetime. I would now like to dynamically read the datetime value from the database, but how would you construct the SSIS to do this?
My first obvious thought would be to simply execute a SQL task to get the datetime and store it in the variable, but got the "differs from the current variable type" error.
Is there a simple way to convert the database datetime into a String variable?
Any help from the community would be appreciated,
I would like an xsl that replaces the value attribute of the data elements only if the relevant param names are passed.
Input
<applicationVariables applicationServer="tomcat">
<data name="HOST" value="localhost"/>
<data name="PORT" value="8080"/>
<data name="SIZE" value="1000"/>
</applicationVariables>
So for example if passing in a param HOST1=myHost and PORT=9080 the output should be:
<applicationVariables applicationServer="tomcat">
<data name="HOST" value="myHost"/>
<data name="PORT" value="9080"/>
<data name="SIZE" value="1000"/>
</applicationVariables>
Note that HOST and PORT where replaced but SIZE was not replaced because there was no parameter with name SIZE
Since the list of data elements is long (and may change), i would like a generic way of doing this with xsl
Hi All,
I have a string say string s ="C:\\Data" , I have an array which contains some strings containg "C:\Data" in the beginning i.e. string[] arr = new {"C:\\Data\abc.xml","C:\\Data\Test\hello.cs"};.
I have to remove the string "C:\Data" from each entry and have to combine it with another string say string fixed = "D:\\Data".
What is the best way to do it, please help as I am a new programmer in C#.
Hello here I have a big problem that I hope to find help
here I have two entities
@Entity
@Inheritance(strategy=InheritanceType.JOINED)
@DiscriminatorColumn(name="Role", discriminatorType=DiscriminatorType.STRING)
public class Utilisateur implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name="id")
private Long id;
@Column(name="nom",nullable=false)
private String nom;
@Column(name="Role",nullable=false, insertable=false)
private String Role ;
//...
}
@Entity
@Table(name="ResCom")
@DiscriminatorValue("ResCom")
public class ResCom extends Utilisateur {
/...
}
the first thing I do
ResCom rsCom= new ResCom(nom,prenom, email,civilite,
SysQl.crypePasse(pass));
gr.create(rsCom);
I check my database I see that property is ResCom insert
but when I check the value of role I get null
Utilisateur tets= gr.findByEmail(email);
message=tets.getEmail()+" and Role :"+tets.getRole()+"";
but in my bass it ResCom !!!!!
the problem disappears when I deploy the project again
I hope you have a solution
And thank you in advance
sorry for my English
I am new to .Net and I am working on one task. Below is my scenario.
I have 2 tables:
Table 1: Students
StudentID StudentDetail
1 StudentName
2 StudentGrade
Table 2: Student_data
StudentDetail StudentRecords
StudentName John (Default)
StudentName Jacob
StudentName Smith
StudentGrade A (default)
StudentGrade B
StudentGrade C
Question: When window form loads (run time) I need to display StudentRecords in combo box with StudentName = "John" and StudentGrade = "A" as default followed by other values.
StudentName and StudentRecords are in Labels and values are in a ComboBox.
I am using VB.Net and VS 2010 with SQL 2008r2.
I would appreciate any step by step help. Apologies If my request is simple.
Hi, I am learning cakephp by myself. I tried to create a user controller with a changepassword function. It works, but I am not sure if this is the best way, and I could not googled up useful tutorials on this.
Here is my code:
class UsersController extends AppController {
var $name = 'Users';
function login() {
}
function logout() {
$this->redirect($this->Auth->logout());
}
function changepassword() {
$session=$this->Session->read();
$id=$session['Auth']['User']['id'];
$user=$this->User->find('first',array('conditions' => array('id' => $id)));
$this->set('user',$user);
if (!empty($this->data)) {
if ($this->Auth->password($this->data['User']['password'])==$user['User']['password']) {
if ($this->data['User']['passwordn']==$this->data['User']['password2']) {
// Passwords match, continue processing
$data=$this->data;
$this->data=$user;
$this->data['User']['password']=$this->Auth->password($data['User']['passwordn']);
$this->User->id=$id;
$this->User->save($this->data);
$this->Session->setFlash('Password changed.');
$this->redirect(array('controller'=>'Toners','action' => 'index'));
} else {
$this->Session->setFlash('New passwords differ.');
}
} else {
$this->Session->setFlash('Typed passwords did not match.');
}
}
}
}
password is the old password, passwordn is the new one, password2 is the new one retyped.
Is there any other, more coomon way to do it in cake?
I cannot get jquery's ajaxSend (http://api.jquery.com/ajaxSend/) to properly modify the parameters. I have:
$(document).ajaxSend(function(event, request, settings) {
settings.data = $.deparam(settings.data);
settings.data['random'] = new Date().getTime();
settings.data['_method'] = 'get';
settings.data = $.param(settings.data)
$.log(settings);
});
$(document).ready(function() {
//...snip...
$.ajaxSetup({
data : {
remote : 1,
authenticity_token : encodeURIComponent(AUTH_TOKEN)
}
});
});
The idea here is that we always want 4 param sent across: remote and auth_token always get set properly. However, random and _method (both needed for IE issues) do not get set. Logging settings inside ajaxSend shows me that they are set to settings.data:
"remote=1&authenticity_token=6GA9R_snip_253D&random=1270584905846&_method=get"
but when it gets sent across the wire, I only have the following:
authenticity_token 6GA9R_snip_253D
remote 1
Why in the world is this not working?
Hi all,
Am a beginner in objective C, i am implementing a function that would query a web server and display the returning string in console. I am calling the function (getDatafromServer) repeatedly in a loop. The problem is that the first time am getting the value whereas the other times, it returns me a (null) in console... I've searched about memory management and check out on the forums but none have worked. Can you please guys tell me where am wrong in the codes below? Thanks in advance....
@implementation RequestThread
+(void)startthread:(id)param{
while (true) {
//NSLog(@"Test threads");
sleep(5);
NSLog(@"%@",[self getDatafromServer]);
}
}
+(NSString *) getDatafromServer{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSString *myRequestString = @"name=Hello%20&[email protected]";
NSData *myRequestData = [NSData dataWithBytes:[myRequestString UTF8String] length:[myRequestString length]];
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL: [NSURL URLWithString:@"http://192.168.1.32/gs/includes/widget/getcalls.php?user=asdasd&passw=asdasdasd"]];
[request setHTTPMethod:@"POST"];
[request setHTTPBody: myRequestData];
[request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"content-type"];
NSData *returnData = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];
NSString *myString = [NSString stringWithUTF8String:[returnData bytes]];
[myRequestString release];
[request release];
[returnData release];
return myString;
[pool release];
}
@end
as topic, I just want create new Entity(table) in sqlite ,
my code as follows:
+(BOOL)CreateDataSet:(NSManagedObjectModel *) model
attributes:(NSDictionary*)attributes
entityName:(NSString*) entityName
{
NSEntityDescription *entityDef = [[NSEntityDescription alloc] init];
[entityDef setName:entityName];
[entityDef setManagedObjectClassName:entityName];
[model setEntities:[NSArray arrayWithObject:entityDef]];
//@step
NSArray *properties = [CoreDataHelper CreateAttributes:attributes];
[entityDef setProperties:properties];
[entityDef release];
return TRUE;
}
but it throw errors:
Terminating app due to uncaught exception 'NSInternalInconsistencyException',
reason: 'Can't modify an immutable model.'
* Call stack at first throw:
(
0 CoreFoundation 0x01c5abe9 __exceptionPreprocess + 185
1 libobjc.A.dylib 0x01daf5c2 objc_exception_throw + 47
2 CoreData 0x0152634a -[NSManagedObjectModel(_NSInternalMethods) _throwIfNotEditable] + 106
3 CoreData 0x01526904 -[NSManagedObjectModel setEntities:] + 36
....
that seem show the model is read only.....
anyone can help on this problem? thanks
I know this is a long shot, but does anyone know of a dataset of English words that has stress information by syllable? Something as simple as the following would be fantastic:
AARD vark
A ble
a BOUT
ac COUNT
AC id
ad DIC tion
ad VERT ise ment
...
Thanks in advance!
This Question has been asked before:
http://stackoverflow.com/questions/2936626/how-to-share-a-dictionary-between-multiple-processes-in-python-without-locking
However I have several doubts regarding the program given in the answer:
The issue is that the following step isn't atomic
d['blah'] += 1
Even with locking the answer provided in that question would lead to random results.
Since
Process 1 read value of d['blah'] saves it on the stack increments it and again writes it.
In Between a Process 2 can read the d['blah'] as well.
Locking means that while d['blah'] is being written or read no other process can access it.
Can someone clarify my doubts?
This is probably a super simple question, but I'm struggling to come up with the right keywords to find it on Google.
I have a Postgres table that has among its contents a column of type text named content_type. That stores what type of entry is stored in that row.
There are only about 5 different types, and I decided I want to change one of them to display as something else in my application (I had been directly displaying these).
It struck me that it's funny that my view is being dictated by my database model, and I decided I would convert the types being stored in my database as strings into integers, and enumerate the possible types in my application with constants that convert them into their display names. That way, if I ever got the urge to change any category names again, I could just change it with one alteration of a constant. I also have the hunch that storing integers might be somewhat more efficient than storing text in the database.
First, a quick threshold question of, is this a good idea? Any feedback or anything I missed?
Second, and my main question, what's the Postgres command I could enter to make an alteration like this? I'm thinking I could start by renaming the old content_type column to old_content_type and then creating a new integer column content_type. However, what command would look at a row's old_content_type and fill in the new content_type column based off of that?
hello,
i need ur help guys..i m making website for 'home docor ideas'..i have a log in form(login-form.php) in which when 'log in' and 'password' is inserted,after verification through login-execute.php, redirected to viewOrder.php where user can view all of the orders ordered by clients.. all is fine up till here.. but what i want is,when user get logged in ,he view only that order which is ordered by him not all customer's orders.. two tables are there in database: members and order_insert.. in 'members' table, login and password is stored and in 'order_insert',orders of customers is stored.. codes of these three pages is as follows..
.........................
login-form.php
.........................
<form id="loginForm" name="loginForm" method="post" action="login-exec.php">
<table width="300" border="0" align="center" cellpadding="2" cellspacing="0">
<tr>
<td width="112"><b>Login</b></td>
<td width="188"><input name="login" type="text" class="textfield" id="login" /></td>
</tr>
<tr>
<td><b>Password</b></td>
<td><input name="password" type="password" class="textfield" id="password" /></td>
</tr>
<tr>
<td> </td>
<td><input type="submit" name="Submit" value="Login" /></td>
</tr>
</table>
</form>
.........................
login-execute.php
.........................
<?php
//Start session
session_start();
//Include database connection details
require_once('config.php');
//Array to store validation errors
$errmsg_arr = array();
//Validation error flag
$errflag = false;
//Connect to mysql server
$link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);
if(!$link) {
die('Failed to connect to server: ' . mysql_error());
}
//Select database
$db = mysql_select_db(DB_DATABASE);
if(!$db) {
die("Unable to select database");
}
//Function to sanitize values received from the form. Prevents SQL injection
function clean($str) {
$str = @trim($str);
if(get_magic_quotes_gpc()) {
$str = stripslashes($str);
}
return mysql_real_escape_string($str);
}
//Sanitize the POST values
$login = clean($_POST['login']);
$password = clean($_POST['password']);
//Input Validations
if($login == '') {
$errmsg_arr[] = 'Login ID missing';
$errflag = true;
}
if($password == '') {
$errmsg_arr[] = 'Password missing';
$errflag = true;
}
//If there are input validations, redirect back to the login form
if($errflag) {
$_SESSION['ERRMSG_ARR'] = $errmsg_arr;
session_write_close();
header("location: login-form.php");
exit();
}
//Create query
$qry="SELECT * FROM members WHERE login='$login' AND passwd='".md5($_POST['password'])."'";
$result=mysql_query($qry);
//Check whether the query was successful or not
if($result) {
if(mysql_num_rows($result) == 1) {
//Login Successful
session_regenerate_id();
$member = mysql_fetch_assoc($result);
$_SESSION['SESS_MEMBER_ID'] = $member['member_id'];
$_SESSION['SESS_FIRST_NAME'] = $member['firstname'];
$_SESSION['SESS_LAST_NAME'] = $member['lastname'];
session_write_close();
header("location: viewOrder.php");
exit();
}else {
//Login failed
header("location: login-failed.php");
exit();
}
}else {
die("Query failed");
}
?>
.............................
viewOrder.php
..............................
<html>
<body bgcolor="#FFFFFF" >
<?
$host="localhost"; // Host name
$username="root"; // Mysql username
$password=""; // Mysql password
$db_name="mydatabase"; // Database name
$tbl_name="order_insert"; // Table name
$tbl_name2="members";
// connect to server and databases
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
$result = mysql_query("SELECT * FROM $tbl_name ");
print "<center>";
$output .= "<table width=1100 border=1 bordercolor=black>";
$output .= "<tr align=center><td>ID</td><td>First Name</td><td>Last Name</td><td>E Mail</td><td> City </td><td> Country </td><td> Phone</td><td>Decoration Type</td><td>Service Description</td><td>Budget</td><td>Update</td><td>Delete</td></tr>";
$output .= "<th></th><th></th>";
$output .= "</tr>\n\n";
while ($row = mysql_fetch_assoc($result)){
$output .= "<tr>\n";
foreach ($row as $col=>$val){
$output .= " <td>$val</td>\n";
} // end foreach
$keyVal = $row["id"];
$output .= "<td><a href='update.php?ID=$row[orderId]' >Update </a></td>";
$output .= "<td><a href='delete.php?ID=$row[orderId]' >Delete </a></td>";
$output .= "</tr>\n\n";
}// end while
$output .= "</table></center>";
print "$output";
?> <br>
<br>
<center><table > <tr><td>
<form action="home.php"><font color="#FF0000"><input type="submit" name="btn" style="color:#CC0000" value="<--Back" ></font></form></td></tr></table></center>
</body>
</html>
.....
your help and suggestions will be appreciated
So I have Html like this http://trac.edgewall.org/wiki/RecentChanges (I want to create some Flash Track reader which will be opensource)
I need to list in my DataGrid Index of all viki pages in form like
+-----------+--------+
|page name |page url|
+-----------+--------+
| name | url |
+-----------+--------+
After getting some responses, the current situation is that I'm using this tip: http://www.ibm.com/developerworks/xml/library/x-tipbigdoc5.html (Listing 1. Turning ResultSets into XML), and XMLWriter for Java from http://www.megginson.com/downloads/
. Basically, it reads date from the database and writes them to a file as characters, using column names to create opening and closing tags. While doing so, I need to make two changes to the input stream, namely to the dates and numbers.
// Iterate over the set
while (rs.next()) {
w.startElement("row");
for (int i = 0; i < count; i++) {
Object ob = rs.getObject(i + 1);
if (rs.wasNull()) {
ob = null;
}
String colName = meta.getColumnLabel(i + 1);
if (ob != null ) {
if (ob instanceof Timestamp) {
w.dataElement(colName, Util.formatDate((Timestamp)ob, dateFormat));
}
else if (ob instanceof BigDecimal){
w.dataElement(colName, Util.transformToHTML(new Integer(((BigDecimal)ob).intValue())));
}
else {
w.dataElement(colName, ob.toString());
}
} else {
w.emptyElement(colName);
}
}
w.endElement("row");
}
The SQL that gets the results has the to_number command (e.g. to_number(sif.ID) ID ) and the to_date command (e.g. TO_DATE (sif.datum_do, 'DD.MM.RRRR') datum_do). The problems are that the returning date is a timestamp, meaning I don't get 14.02.2010 but rather 14.02.2010 00:00:000 so I have to format it to the dd.mm.yyyy format. The second problem are the numbers; for some reason, they are in database as varchar2 and can have leading zeroes that need to be stripped; I'm guessing I could do that in my SQL with the trim function so the Util.transformToHTML is unnecessary (for clarification, here's the method):
public static String transformToHTML(Integer number) {
String result = "";
try {
result = number.toString();
} catch (Exception e) {}
return result;
}
What I'd like to know is
a) Can I get the date in the format I want and skip additional processing thus shortening
the processing time?
b) Is there a better way to do this? We're talking about XML files that are in the 50 MB - 250 MB filesize category.
I can do this:
SELECT t2.value + sum(t3.value)
FROM tableA t2, tableB t3
WHERE t2.somekey = t3.somekey
GROUP BY t3.somekey
But how to do this?
UPDATE tableA t1
SET speed = (
SELECT t2.value + sum(t3.value)
FROM tableA t2, tableB t3
WHERE t2.somekey = t3.somekey
AND t1.somekey = t3.somekey
GROUP BY t3.somekey
)
;
MySQL says it's illegal since you can't specify target table t1 for update in FROM clause.
The other day I tried out VS2010's SQL compare tools and thought they were awesome.
I am wondering if there is any way to harness these tools in code written in VS 2010.
I'm creating a website using ASP.NET MVC 2 and I'm thinking of using the default AccountController and Views to take care of the Users.
The only problem is that, for all the rest, I'm using a Postgres database.
Is there a way to link The account controller to a User class defined by me?
I'm using Nhibernate to connect to the database, so I'll have a User class with whatever fields necessary.
Thanks very much.
I have 2 features that use a common 'When' step but have different 'Then' steps in different classes.
How do I access, for example, the ActionResult from my MVC controller call in the When step in my two Then steps?
I can not figure out why my code does not filter out lists from a predefined list.
I am trying to remove specific list using the following code.
data = [[1,1,1],[1,1,2],[1,2,1],[1,2,2],[2,1,1],[2,1,2],[2,2,1],[2,2,2]]
data = [x for x in data if x[0] != 1 and x[1] != 1]
print data
My result:
data = [[2, 2, 1], [2, 2, 2]]
Expected result:
data = [[1,2,1],[1,2,2],[2,1,1],[2,1,2],[2,2,1],[2,2,2]]
I'm using Hibernate3.2+Websphere6.0+struts1.3..
After deploying ,application works fine.
After some idle time ,i will get this type of error repeatedly,am not able to login at all.
Im not using any connection pooling. i feel after idle time its not able to connect to the database again..if i restart the server everything works fine for some time...after that same story.. please help me out