Hit a speed bump, trying to update some column values in my table from another table.
This is what is supposed to happen when everything works
Correct all the city, state entries in tblWADonations by creating an update statement that moves the zip city from the joined city/state zip field to the tblWADonations city state
TBL NAME | COLUMN NAMES
tblZipcodes with zip,city,State
tblWADonations with zip,oldcity,oldstate
This is what I have so far:
UPDATE tblWADonations
SET oldCity = tblZipCodes.city, oldState = tblZipCodes.state
FROM tblWADonations INNER JOIN
tblZipCodes ON tblWADonations.zip = tblZipCodes.zip
Where oldCity <> tblZipcodes.city;
There seems to be easy ways to do this online but I am overlooking something. Tried this by hand and in editor this is what it kicks back.
Msg 8152, Level 16, State 2, Line 1
String or binary data would be truncated.
The statement has been terminated.
Please include a sql statement or where I need to make the edit so I can mark this post as a reference in my favorites. Thanks!
I have a Silverlight master-details DataForm where the DataForm represents a street address.
When I edit the Address1 textbox, the value gets automatically committed to the bound Address object once focus leaves the textbox.
If I hit the Cancel button, then any changes are undone because Address implements IEditableObject and saves its state.
The problem is that since any change is immediately propagated to the underlying object it will be shown in the master grid before the user has actually hit Save. I also have other locations where this data is shown. This is not a very good user experience.
I've tried OneWay binding but then I can't commit back without manually copying all the fields over.
The only thing I can think of doing is to create a copy of the data first or using OneWay binding, but they both seem a little clumsy.
Does DataForm support this way of working?
hey guys,
I have a WPF application that contains windows with few user controls and Coordinator object. the window and all its user controls pointing to an object, which instace is in the Coordinator, by thier DataContext.
the problem is that I want to change this object (e.g. create new object()) in the Coordinator but I want all the dataContexts to point to the new object.
I tried to send the object by ref to the window constructor but it didn't help.
any idea about how can I rewrite the memory location that all pointers are pointing to?
(I don't want to repalce the properties in object since its a lot of work nor to use a middle object that points to the replaced object)
Thanks
Eran
I have a string representing an URL containing spaces and want to convert it to an URI object. If is simple try to do
String myString = "http://myhost.com/media/mp3s/9/Agenda of swine - 13. Persecution Ascension_ leave nothing standing.mp3";
URI myUri = new URI(myString);
it gives me
java.net.URISyntaxException: Illegal character in path at index X
where index X is the position of the first space in the URL string.
How can i parse myStringinto a URI object?
How do I manage disposing an object when I use IoC? My case it is Ninject.
// normal explicit dispose
using (var dc = new EFContext)
{
}
But sometimes I need to keep the context longer or between function calls.
So I want to control this behavior through IoC scope.
// if i use this way. how do i make sure object is disposed.
var dc = ninject.Get<IContext>()
// i cannot use this since the scope can change to singleton. right ??
using (var dc = ninject.Get<IContext>())
{
}
Sample scopes
Container.Bind<IContext>().To<EFContext>().InSingletonScope();
Container.Bind<IContext>().To<EFContext>().InRequestScope();
this problem make me crazy!
i have asp.net website it raise periodically this error (in IE8):
System.Web.HttpException: Invalid viewstate.
at System.Web.UI.Page.DecryptStringWithIV(String s, IVType ivType)
at System.Web.Handlers.AssemblyResourceLoader.System.Web.IHttpHandler
.ProcessRequest(HttpContext context)
,...
or (in IE6)
System.FormatException: Invalid length for a Base-64 char array.
at System.Convert.FromBase64String(String s)
at System.Web.UI.ObjectStateFormatter.Deserialize(String inputString)
or (in IE7)
System.FormatException: Invalid character in a Base-64 string.
at System.Convert.FromBase64String(String s)
at System.Web.UI.ObjectStateFormatter.Deserialize(String inputString)
i set enableViewStateMac in web.config to false and defined machinekey in my web.config and defined UTF-8 encoding for every page
but i received this errors.
do you have any solution?
best regards
What is the mysql I need to achieve the result below given these 2 tables:
table1:
+----+-------+
| id | name |
+----+-------+
| 1 | alan |
| 2 | bob |
| 3 | dave |
+----+-------+
table2:
+----+---------+
| id | state |
+----+---------+
| 2 | MI |
| 3 | WV |
| 4 | FL |
+----+---------+
I want to create a temporary view that looks like this
desired result:
+----+---------+---------+
| id | name | state |
+----+---------+---------+
| 1 | alan | |
| 2 | bob | MI |
| 3 | dave | WV |
| 4 | | FL |
+----+---------+---------+
I tried a mysql union but the following result is not what I want.
create view table3 as
(select id,name,"" as state from table1)
union
(select id,"" as name,state from table2)
table3 union result:
+----+---------+---------+
| id | name | state |
+----+---------+---------+
| 1 | alan | |
| 2 | bob | |
| 3 | dave | |
| 2 | | MI |
| 3 | | WV |
| 4 | | FL |
+----+---------+---------+
First suggestion results:
SELECT *
FROM table1
LEFT OUTER JOIN table2 USING (id)
UNION
SELECT *
FROM table1
RIGHT OUTER JOIN table2 USING (id)
+----+---------+---------+
| id | name | state |
+----+---------+---------+
| 1 | alan | |
| 2 | bob | MI |
| 3 | dave | WV |
| 2 | MI | bob |
| 3 | WV | dave |
| 4 | FL | |
+----+---------+---------+
I have got a code snippet as follows:
Dim fstream = new filestream(some file here)
dim bwriter = new binarywriter(fstream)
while not end of file
read from source file
bwriter.write()
bwriter.flush()
end while
The question I have is the following. When I call bwriter.flush() does it also flush the fstream object? Or should I have to explicitly call fstream.flush() such as given in the following example:
while not end of file
read from source file
bwriter.write()
bwriter.flush()
fstream.flush()
end while
A few people suggested that I need to call fstream.flush() explicitly to make sure that the data is written to the disk (or the device). However, my testing shows that the data is written to the disk as soon as I call flush() method on the bwriter object.
Can some one confirm this?
To extend the User object with custom fields, the Django docs recommend using UserProfiles. However, according to this answer to a question about this from a year or so back:
extending django.contrib.auth.models.User also works better now -- ever since the refactoring of Django's inheritance code in the models API.
And articles such as this lay out how to extend the User model with custom fields, together with the advantages (retrieving properties directly from the user object, rather than through the .get_profile()).
So I was wondering whether there is any consensus on this issue, or reasons to use one or the other. Or even what the Django team currently think?
I have the following sample where the SourceData class would represent a DataView resulting from an Sql query:
class MainClass
{
private static SourceData Source;
private static DataView View;
private static DataView Destination;
public static void Main (string[] args)
{
Source = new SourceData();
View = new DataView(Source.Table);
Destination = new DataView();
Source.AddRowData("Table1", 100);
Source.AddRowData("Table2", 1500);
Source.AddRowData("Table3", 1300324);
Source.AddRowData("Table4", 1122494);
Source.AddRowData("Table5", 132545);
Console.WriteLine(String.Format("Data View Records: {0}", View.Count));
foreach(DataRowView drvRow in View)
{
Console.WriteLine(String.Format("Source {0} has {1} records.", drvRow["table"], drvRow["records"]));
DataRowView newRow = Destination.AddNew();
newRow["table"] = drvRow["table"];
newRow["records"] = drvRow["records"];
}
Console.WriteLine();
Console.WriteLine(String.Format("Destination View Records: {0}", Destination.Count));
foreach(DataRowView drvRow in Destination)
{
Console.WriteLine(String.Format("Destination {0} has {1} records.", drvRow["table"], drvRow["records"]));
}
}
}
class SourceData
{
public DataTable Table
{
get{return dataTable;}
}
private DataTable dataTable;
public SourceData()
{
dataTable = new DataTable("TestTable");
dataTable.Columns.Add("table", typeof(string));
dataTable.Columns.Add("records", typeof(int));
}
public void AddRowData(string tableName, int tableRows)
{
dataTable.Rows.Add(tableName, tableRows);
}
}
My output is:
Data View Records: 5
Source Table1 has 100 records.
Unhandled Exception: System.NullReferenceException: Object reference not set to an instance of an object at System.Data.DataView.AddNew () [0x0003e] in /usr/src/packages/BUILD/mono-2.4.2.3
/mcs/class/System.Data/System.Data/DataView.cs:344 at DataViewTest.MainClass.Main (System.String[] args) [0x000e8] in /home/david/Projects/DataViewTest/SourceData.cs:29
I did some reading here: DataView:AddNew Method...
...and it would appear that I am doing this the right way. How come I am getting the Object reference not set?
I have an entityDao that is inherbited by everyone of my objectDaos. I am using Dynamic Linq and trying to get some generic queries to work.
I have the following code in my generic method in my EntityDao :
public abstract class EntityDao<ImplementationType> where ImplementationType : Entity
{
public ImplementationType getOneByValueOfProperty(string getProperty, object getValue){
ImplementationType entity = null;
if (getProperty != null && getValue != null)
{
LCFDataContext lcfdatacontext = new LCFDataContext();
//Generic LINQ Query Here
entity = lcfdatacontext.GetTable<ImplementationType>().Where(getProperty + " =@0", getValue).FirstOrDefault();
//.Where(getProperty & "==" & CStr(getValue))
}
//lcfdatacontext.SubmitChanges()
//lcfdatacontext.Dispose()
return entity;
}
}
Then I do the following method call in a unit test (all my objectDaos inherit entityDao):
[Test]
public void getOneByValueOfProperty()
{
Accomplishment result = accomplishmentDao.getOneByValueOfProperty("AccomplishmentType.Name", "Publication");
Assert.IsNotNull(result);
}
The above passes (AccomplishmentType has a relationship to accomplishment)
Accomplishment result = accomplishmentDao.getOneByValueOfProperty("Description", "Can you hear me now?");
Accomplishment result = accomplishmentDao.getOneByValueOfProperty("LocalId", 4);
Both of the above work
Accomplishment result = accomplishmentDao.getOneByValueOfProperty("Id", New Guid("95457751-97d9-44b5-8f80-59fc2d170a4c"))
Does not work and says the following:
Operator '=' incompatible with operand types 'Guid' and 'Guid
Why is this happening? Guid's can't be compared? I tried == as well but same error. What's even moreso confusing is that every example of Dynamic Linq I have seen simply usings strings whether using the parameterized where predicate or this one I have commented out:
//.Where(getProperty & "==" & CStr(getValue))
With or without the Cstr, many datatypes don't work with this format. I tried setting the getValue to a string instead of an object as well, but then I just get different errors (such as a multiword string would stop comparison after the first word).
What am I missing to make this work with GUIDs and/or any data type? Ideally I would like to be able to just pass in a string for getValue (as I have seen for every other dynamic LINQ example) instead of the object and have it work regardless of the data Type of the column.
I am working on some code using the EMF framework in Java, but it is really hard to use, e.g. I cannot implement OCL-like query API on top of EMF which would be type-safe. One of the reasons is that eGet() for a EStructuralFeature return just an Object, not EObject. So anything I would write must use much of null checking, type checking and type casting which is unsafe, not performant and cannot be generalized in a reusable way. Why doesn't EMF generate dummy implementations with EObject wrappers for arbitrary Object value? Implementing the EObject and hence the EClass interfaces even with simple throw UnsupportedOperationException is really a pain (the APIs are too big). The same holds for the eContainer() method which makes navigatinng the model upwards painful.
I'm trying to test whether a user is registered on FreeNode. nick_info() doesn't seem to return information about this, so I want to use $irc-yield(whois = $nick); and then grab the irc_whois event's reply. The problem is that I want to wait until this event is fired, so I created a global variable $whois_result and wrote a sub like this:
sub whois {
my $nick = $_[0];
$whois_result = 0;
$irc->yield(whois => $nick);
while($whois_result == 0) { }
return $whois_result;
}
with the irc_whois handler looking like:
sub on_whois {
$whois_result = $_[ARG0];
print "DEBUG: irc_whois fired.\n";
}
Unfortunately, the event can't fire while the loop is running so this hangs. I'm sure there's a better way to do this, but I'm not familiar enough with this kind of programming to know. Any help would be greatly appreciated.
Hi everyone,
I'm working in Visual Studio 2008 using c#.
Let's say I have 2 xsd files e.g "Envelope.xsd" and "Body.xsd"
I create 2 sets of classes by running xsd.exe, creating something like "Envelope.cs" and "Body.cs", so far so good.
I can't figure out how to link the two classes to serialize (using XmlSerializer) into the proper nested xml, i.e:
I want:
<Envelope><DocumentTitle>Title</DocumentTitle><Body>Body Info</Body></Envelope>
But I get:
<Envelope><DocumentTitle>Title</DocumentTitle></Envelope><Body>Body Info</Body>
Could someone perhaps show me how the two .cs classes should look to enable XmlSerializer to runt the desired nested result?
Thanks a million
Paul
So I try to build a Model-View window using QTDesigner and C++.
For that reason I created a QOBject derived class as my model. It provides slots and signals to access it like: setFileName(QString) or fileNameChanged(QString).
I got a little into using signal drag and drop in QTDesigner and found it quite VA-Smalltalk-Like nice. After a while I was wondering if I could also connect my model to this. So is it possible to somehow introduce my model object into the Window/GUI and let QTDesigner connect signals and slots from the model object to the GUI.
In essence: Write for me:
connect( model, SIGNAL(fileNameChanged(QString)), ui->labelFn, SLOT(setText(QString)))
connect( ui-textEdit2, SIGNAL(textChanged(QString)), model, SLOT(setFileName(QString)))
Thanks for explaining
I am using Rulesets on a type that looks like this:
public class Salary
{
public decimal HourlyRate { get; set; }
[ValidHours] //Custom validator
public int NumHours { get; set; }
[VerifyValidState(Ruleset="State")] //Custom validator with ruleset
public string State { get; set; }
}
Due to business requirements, I'd need to first validate the ruleset "State" and then validate the entire business entity
public void Save()
{
ValidationResults results = Validation.Validate(salary, "State");
//Check for validity
//Now run the validation for ALL rules including State ruleset
ValidationResults results2 = Validation.Validate(salary); //Does not run the ruleset marked with "State"
}
How do I accomplish what I am trying to do?
Consider this topic a sequel of the following topic:
Previous Installment
Undefined Behavior and Sequence
Points
Let's revisit this funny and convoluted expression (the italicized phrases are taken from the above topic *smile* ):
i += ++i;
We say this invokes undefined-behavior. I presume that when say this, we implicitly assume that type of i is one of built-in types.
So my question is: what if the type of i is a user-defined type? Say it's type is Index which is defined later in this post (see below). Would it still invoke undefined-behavior?
If yes, why? Is it not equivalent to writing i.operator+=(i.operator ++()); or even syntactically simpler i.add(i.inc());? Or, do they too invoke undefined-behavior?
If no, why not? After all, the object i gets modified twice between consecutive sequence points. Please recall the rule of thumb : an expression can modify an object's value only once between consecutive "sequence points. And if i += ++i is an expression, then it must invoke undefined-behavior. If so, then it's equivalents i.operator+=(i.operator ++()); and i.add(i.inc()); must also invoke undefined-behavior which seems to be untrue! (as far as I understand)
Or, i += ++i is not an expression to begin with? If so, then what is it and what is the definition of expression?
If it's an expression, and at the same time, it's behavior is also well-defined, then it implies that number of sequence points associated with an expression somehow depends on the type of operands involved in the expression. Am I correct (even partly)?
By the way, how about this expression?
a[++i] = i; //taken from the previous topic. but here type of `i` is Index.
class Index
{
int state;
public:
Index(int s) : state(s) {}
Index& operator++()
{
state++;
return *this;
}
Index& operator+=(const Index & index)
{
state+= index.state;
return *this;
}
operator int()
{
return state;
}
Index & add(const Index & index)
{
state += index.state;
return *this;
}
Index & inc()
{
state++;
return *this;
}
};
Can Automapper map values from a NameValueCollection onto an object, where target.Foo receives the value stored in the collection under the "Foo" key?
I have a business object that stores some data in named properties and other data in a property bag. Different views make different assumptions about the data in the property bag, which I capture in page-specific view models. I want to use AutoMapper to map both the "inherent" attributes (the ones that always exist) as well as the "dynamic" attributes (the ones that vary per view and may or may not exist).
Consider the bellow code. This code is supposed to be processing data at a fixed rate, in one second batches, It is part of an overal system and can't take up too much time.
When running over 100 lots of 1 seconds worth of data the program takes 35 seconds (or 35%), executing this function in a loop. The test loop is timed specifically with Ada.RealTime. The data is pregenerated so the majority of the execution time is definatetly in this loop.
How do I improce the code to get the processing time down to a minimum?
The code will be running on an Intel Pentium-M which is a P3 with SSE2.
package FF is new Ada.Numerics.Generic_Elementary_Functions(Float);
N : constant Integer := 820;
type A is array(1 .. N) of Float;
type A3 is array(1 .. 3) of A;
procedure F(state : in out A3;
result : out A3;
l : in A;
r : in A) is
s : Float;
t : Float;
begin
for i in 1 .. N loop
t := l(i) + r(i);
t := t / 2.0;
state(1)(i) := t;
state(2)(i) := t * 0.25 + state(2)(i) * 0.75;
state(3)(i) := t * 1.0 /64.0 + state(2)(i) * 63.0 /64.0;
for r in 1 .. 3 loop
s := state(r)(i);
t := FF."**"(s, 6.0) + 14.0;
if t > MAX then
t := MAX;
elsif t < MIN then
t := MIN;
end if;
result(r)(i) := FF.Log(t, 2.0);
end loop;
end loop;
end;
psuedocode for testing
create two arrays of 80 random A3 arrays, called ls and rs;
init the state and result A3 array
record the realtime time now, called last
for i in 1 .. 100 loop
for j in 1 .. 80 loop
F(state, result, ls(j), rs(j));
end loop;
end loop;
record the realtime time now, called curr
output the duration between curr and last
I have a directory structure with the following on localhost:
http://localhost/testing/
A directory structure exists inside of testing as follows:
/testing/public
/testing/public/index.php
/testing/public/img
/testing/public/css
..etc for the js and swf directories
A .htaccess file is inside the testing folder and the contents are as follows:
Options +FollowSymLinks
RewriteEngine on
RewriteBase /testing/
RewriteRule ^public$ public/ [R,QSA]
RewriteRule ^public/$ public/index.php?state=public [L,QSA]
RewriteRule ^stackoverflow$ stackoverflow/ [R,QSA]
RewriteRule ^stackoverflow/$ public/index.php?state=stackoverflow[L,QSA]
I am using PHP and inside of the /testing/public/index.php file I wanted to test that the $_GET['state'] is indeed saving the variable.
When I try to test out:
http://localhost/testing/public
$_GET['state'] is not found at all BUT
http://localhost/testing/stackoverflow
does indeed echo out that $_GET['state'] equals 'stackoverflow'.
What am I missing here??? Why is it that I cannot get the state=public in the first link? Thanks for the help!
Hi folks,
For my trading program, I have a Merchant class. A given Merchant object may or may not have a particular special quality or bundle of special qualities. For example, one Merchant object may have the Stockbroker quality, another Merchant may have the Financial Services and Stockbroker qualities, and another Merchant may have no special qualities at all.
My initial thought was to create a HashMap and a Qualities class as follows:
Map<Qualities, Boolean> merchantQualities = new HashMap<Qualities, Boolean>();
The only problem is, there are at least 50 possible special qualities for Merchants, such that it would be extremely tiresome to subclass all the qualities from the Quality class.
Is there a better way of coding for these optional special qualities and representing them in the Merchants class than a HashMap and subclassing a Qualities class?
How do I get the collection of errors in a view?
I don't want to use the Html Helper Validation Summary or Validation Message. Instead I want to check for errors and if any display them in specific format. Also on the input controls I want to check for a specific property error and add a class to the input.
P.S. I'm using the Spark View Engine but the idea should be the same.
So I figured I could do something like...
<if condition="${ModelState.Errors.Count > 0}">
DispalyErrorSummary()
</if>
....and also...
<input type="text" value="${Model.Name}" class="?{ModelState.Errors["Name"] != string.empty} error" />
....
Or something like that.
UPDATE
My final solution looked like this:
<input type="text" value="${ViewData.Model.Name}" class="text error?{!ViewData.ModelState.IsValid && ViewData.ModelState["Name"].Errors.Count() > 0}" id="Name" name="Name" />
This only adds the error css class if this property has an error.