|
Hi All,
I will be honest with you - I have taken exactly 1 ASP.NET class (instructional class...not object class, haha), so I might be doing this all wrong. I am developing an online employment application for the company that I work for. In my ASP.NET class, they taught us to try and avoid having our .aspx pages speak directly to the database (which I had always done before), so I am trying my best to use that best practice, but this is my first time doing it like this, and there's still some issues I'm trying to work out. I started building this application like I used to build all my other applications...but I think I need help from some more seasoned professionals on how to streamline what I've done in the past to make it fit what I'm trying to do now.
The way I organize my data is like this:
* DatabaseMethods.cs - class I created that connects to the database and has a queryDatabase(String query){} method that I use for sending queries and retrieving results (it returns DataTable objects that I work with when I send SELECT queries.)
* DataMethods.cs - class I created that has DataTable objects inside it for each of the data tables I'm interested in. This class accepts an instance of DatabaseMethods as a parameter in its constructor. Then, I have methods in here for pulling information out of my database and into my DataTable objects when I need them. (i.e. loadNames(){} would load the Names table from the database into the DataTable object Names in my DataMethods object.) My applications are typically fairly small, but I still usually parameterize these load***() methods so that the select queries aren't pulling entire tables in...my DBA would kill me...and since I am the DBA...that would be a form of suicide.
* I place instances of the DatabaseMethods object and the DataMethods object in the code-behind on my Master page. That way, throughout the whole application, on all the various screens, if I need, say, my Names table, I can just go like this: Master.DataMethods.loadNames(); Master.Names.Rows[0]["firstName"]; If I needed the first name field in the first row of that database table, for example.
* What I've now added are objects for my data, and an ObjectMethods.cs class for loading up those objects. All the objects themselves contain are their default constructors, the data fields I'm interested in for them, and methods that load a particular object from the database based on its ID, and methods that save that particular object to the database, whether by updating an existing row or inserting a new one. I sort of correlate objects to database rows. I wasn't sure how else to do that.
So, now that you understand how my application structure is organized (or messed up, depending on how you look at it - and I am welcome to suggestions on how to improve this), here is where my problem with the ObjectDataSource is:
I have a user control called RelativeSupervisorsRecordView.ascx, which has fields for last name, first name, middle name, and relationship. This is where applicants will enter in any supervisors at our company who are related to them, and how. The user can click an add button to get as many or few of these user controls as they want, in case they have anywhere from zero to a zillion relatives that are supervisors at my company.
The Relationship part of this user control is the issue. The relationship is a database table with ids 1 through 8, and values like Parent, Cousin, Child, Granparent, etc.
My user control connects to my Master page and calls the loadRelationshipTypes() method inside of my ObjectMethods class. That method, in turn, calls loadRelationshipTypes() in my DataMethods.cs class, which populates my Relationships data table. Then, the ObjectMethods class takes that data, creates 8 relationship objects out of it, and returns the objects in an IList<relationshiptypes> to my user control. Then, in the Page_Load method, my user control binds that IList to the DropDownList inside itself. When I watch this happen in debug mode, stepping through the code, everything looks good. The data is coming from the database ok, the objects are being created okay, I'm not seeing any exceptions generated on the DataBind command after I set the datasource property of the dropdownlist control, and all looks well. Then, when the page displays, my drop down list has nothing in it. What gives?
If code would make it easier, let me know and I'll post it.
|
|
|
|
|
Say I create a unit test that looks something like this below (autogenerated by VS) to test:
[TestMethod()]
public void UniContexPipeDataTest()
{
IResponse response = null; // TODO: Initialize to an appropriate value
ISeries series = null; // TODO: Initialize to an appropriate value
DateTime asof = new DateTime(); // TODO: Initialize to an appropriate value
UniContext target = new UniContext(response, series, asof);
target.PipeData();
Assert.Inconclusive("TODO: Implement code to verify target");
}
I know I have to initialize response and series but they are big and have lots of other objects and Interfaces embedded within them that need to be instantiated for the UniContext contructor and PipeData() to work correctly.
Q. How do I get the interfaces ready so that the constructor and method PipeData() pass in this unit test?
Right now I can create these objects and interfaces to pass into the target but they will be empty. Both IResponse and ISeries have tons of embedded interfaces and other things like other objects and properties inside them that need to be created and instantiated with data.
Do I need to start with the embedded object first and then do a ordered test unit test type deal?
Do I need to learn about stubs, external dependencies and creating mocks objects?
Any help/advice on this will be appreciated.
--------------------------------------------------------------------------------
|
|
|
|
|
Hi,
I need to make a Lucene exact case insensitive keyword match query.
I tried BooleanQuery to combine TermQuery and WildcardQuery. but it's case sensitive ...
Sample :
Keyword : Business -> Got Results
Keyword : business -> No results
please guide me to achieve this. Thanks in advance.
|
|
|
|
|
Try applying the LowerCaseFilter to your search. Have a look at this[^] article for details.
|
|
|
|
|
This is dealing with a string "The Quick Brown Fox Jumped Over the Lazy Dog.".
But, in my project, I created index files for a bulk data and would like to search for a string using index files. I'm expecting the output ignoring case sensitivity. Please guide me to get this.
Thank you.
|
|
|
|
|
I'd like to serialize this func property of my class.
public Func<object, object, object> CostAdditionFunction { get; set; }
But if I add the [DataMember(Order = 6)] attribute to use DataContract serialisation, I get the following error:
Type 'System.DelegateSerializationHolder+DelegateEntry' with data contract name 'DelegateSerializationHolder.DelegateEntry:http://schemas.datacontract.org/2004/07/System' is not expected. Consider using a DataContractResolver or add any types not known statically to the list of known types - for example, by using the KnownTypeAttribute attribute or by adding them to the list of known types passed to DataContractSerializer.
Not entirely sure I understand the error, or how to resolve it...
The reason for this request is that there is a related class with a object Cost property, and because I don't know the actual type of Cost, I can't just do Cost + Cost as the object might not have a + operator defined. So the func allows me do things like CostAdditionFunction = (s, t) => ((int) s) + ((int) t); .
btw I did try using Generics to solve this as well, but that didn't work when I was trying to provide the GUI layer for these classes. But if I'm doing something utterly stupid, I'll consider alternatives!
|
|
|
|
|
I have converted my C# visual studio 2003 project to visual studio 2010(framework 4.0).
I debugged the code and finally got success to run my application. Every thing in the application seems to be proper functional, but crystal reports. When i opened the crystal report in designer mode it is opening in some sort of format that is unreadable, as i think the crystal reports could not be converted. Is there any way to get all my reports back in designer view, so that i can save my time from being designing again all my reports.
Thanks in Advance
Regards
|
|
|
|
|
Hi all,
I am using datagridview in c# windows application.I having a .dat file,i have to read the extract the data from that file and display in datagridview with checkbox's and the data.
How can i do it.
Thanks in advance.
|
|
|
|
|
You need to move the data into a container of some description. A List<>, datatable or an array and then bind that data a s the datasource to the DGV.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
How do I write a C# code to calculate the average of all scores entered between 0 and 100. Use a sentinel – controlled loop variable to terminate the loop. After values are entered and the average calculated, test the average to determine whether an A, B, C, D, or F should be recorded. The scoring rubric is as follows:
A 90-100
B 80-89
C 70-79
D 60-69
F < 60
N.B Am very new to programming language and I am interested to become C# programmer.
your kind assistance in solving this problem will be appreciated.
DammyMulero
|
|
|
|
|
DammyMulero wrote: Am very new to programming language and I am interested to become C# programmer.
In that case you should start at the beginning and study the language basics before trying more advanced projects. I would suggest .NET Book Zero[^] as a great place to begin your studies.
|
|
|
|
|
|
Go here [^]
".45 ACP - because shooting twice is just silly" - JSOP, 2010 ----- You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010 ----- "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass." - Dale Earnhardt, 1997
|
|
|
|
|
Hope he gets the picture
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
You're question looks like a homework question which in itself is not a reason for downvoting, but the lack of information is.
You have a problem (real life or homework doesn't matter) and you need an answer. What did you do to solve this problem yourself? Is the problem here that you have tried some things, but couldn't? And why not? Or don't you know how or where to start? If you want to start out programming you must have a certain idea of what you want and what direction you will take, correct? So what is that?
To answer the question, I'm a beginner I don't know where to start.
Buy a book. seriously, the internet is not good to learn new stuff from scratch. When you start out on chapter one, it will probably guide you through a "Hello World" program and gradually work up to a higher level. The problem you have here will be solved before you reach the end of the book, it's pretty basic. If you do have a problem with an exercise, come back here and ask the question, explaining what you did and ask what you can do to solve it.
Hope this helps.
V.
|
|
|
|
|
DammyMulero wrote: How do I write a C# code
By first learning the language of choice, C# in this case. Then you may begin by making notes on pieces of paper. But eventually you will need to enter the actual code in some sort of text editor (such as Notepad), perhaps even a full-blown and very complex application called an "Integrated Development Environment", but that may be beyond your abilities at this point.
|
|
|
|
|
Hi.
Please consider the following fixed values...
unsigned int value1 = 396;
unsigned int value2 = 398565;
1) The above values will change, but value1 will always be 3 digits, and value2 will always be 6 digits.
How do I....
A) Place both values into one DWORD?
b) Encode it as a 4 byte array.
So, as an example (not actual values)
396 + 398565 -> (DWORD) = 396398565 -> BYTE[] = {0x00, 0x00, 0x00, 0x00 } (whatever the hex would be)
And then, I would need to reverse it, although I think I have the code working to do that, but cant test it properly until I can get the above to work.
Thank you,
Steve
|
|
|
|
|
I still don't see why you insist on the array of bytes.
Here's a rather simple way without unsafe code:
uint a = 396 ;
uint b = 398565 ;
uint c = ( a << 20 ) | ( b & 0x0FFFFFu ) ;
byte[] d = new byte [ sizeof(uint) ] ;
for ( int i = 0 ; i < d.Length ; i++ )
{
d [ i ] = (byte ) ( ( c >> 8 * i ) & 0x0FF ) ;
}
uint e = 0 ;
for ( int i = 0 ; i < d.Length ; i++ )
{
e |= (uint) ( d [ i ] << 8 * i ) ;
}
uint f = e >> 20 ;
uint g = e & 0x0FFFFFu ;
|
|
|
|
|
FYI: I know you're not fond of converter classes, however
BitConverter.GetBytes() and
BitConverter.ToUInt32() are exactly what you want here.
|
|
|
|
|
Luc Pattyn wrote: what you want
What I want?
Actually, I also looked at some code I wrote a while back that does that sort of thing, and I found that the existing tools didn't work properly with some types (e.g. enumerations, DateTime), so I wrote my own.
Here's a taste of that technique:
private static unsafe byte[]
ToByteArray
(
object Value
,
byte[] Buffer
)
{
System.Runtime.InteropServices.GCHandle h =
System.Runtime.InteropServices.GCHandle.Alloc
( Value , System.Runtime.InteropServices.GCHandleType.Pinned ) ;
try
{
byte* b = (byte*) h.AddrOfPinnedObject().ToPointer() ;
for ( int i = 0 ; i < Buffer.Length ; i++ )
{
Buffer [ i ] = b [ i ] ;
}
}
finally
{
h.Free() ;
}
return ( Buffer ) ;
}
I may have to try this BitConverter, but I doubt I'll like it.
What I presented, though, is obviously very simple, about the minimum required for the stated task.
|
|
|
|
|
Hi Luc,
This time I was going to use BitCOnverter, but because the first problem was to get 2 int values into one uint, uint32 or whatever I would need, and then convert to a byte array.
Thank you,
Stephen
|
|
|
|
|
Ah, I see that the BitConverter only works with a few, rarely used, datatypes (and not strings! ) -- I want (not need) a more general solution.
|
|
|
|
|
Hi.
This does not seem to work.
It produces the following uint:
129098304
and I need 396398565
Thank you,
Stephen
|
|
|
|
|
|
BitConverter.GetBytes(a + 1000000*b)
|
|
|
|
|