|
and by the way. What I was talking about is loading a database record into a class from a generic base class.
So you'd create
public class GenericClass
{
public virtual void Load();
public virtual void Update();
}
Inside update you would test to see if the class has an id. If it does then this is not a new class otherwise it is.
I usually make my stored procs do update and inserts inside the same proc for less code to keep up with.
if constructor looks like so
public GenericClass( int id ) ** assuming the class uses an int id(indentity field)
{
Load(id);
}
this way all classes pass in an id to create
from your program
Player p = new Player(1); <-- has an id of 1
so when you run this code. It processes the PlayerClass Contructor for custom stuff first. then calls the Generic contructor with the ID. The Generic class then load the data into the class
By the way the PlayerClass construction should look somthing like
public PlayerClass( int id ) : ( id ) {}
the second will call the base class's constructor with the id
Thats the basics of it. If thats the path your going, I can help you with the code inside Save and Load. But you need to understand what this accomplishes from a high level. And of course, if this is what your trying to do.
Nick
--------------------------------------------------------
1 line of code equals many bugs. So don't write any!!
My mad coder blog
|
|
|
|
|
So by 1:1 you mean 1 player in the db equals one instance of player class in the code right?
So there would pretty much be a class for each table (or useful table that is not just foreign keys).
I was concerned by using stored procedures to insert and update since in C# i would have to sort out the paramaters for the variables, so if the db changed i would have to change the stored proc and have to change the code as well, wheras if i just used insert and update statements with ExecuteNonQuery of an SqlCommand object i would only have to change the code. At the moment in my Database class i am using an SqlDataAdapter to fill a DataSet and returning that dataset for SELECT statements. For other SQL statements i just execute the SQL.
As for the generic class, could this only handle like table, e.g. ones like you say that use an IDENTITY column or could it handle and table?
|
|
|
|
|
|
Not actually.
Typically you use a datareader that populates the class via reflection.
You can use Typed datasets. But thier huge, bulky, and have been proven to fail and force a re-write in the business world.
I hear they dont work well with workflows. I avoid them like the plague after seeing thier issues first hand a year ago.
But, its your code. And you still need to create an interface and .net comes with a class generator so You don't really save anytime using datasets.
The updating code is 10 lines or so.
Good luck with whatever you choose I would read about real world example with OMG www.omg.org they are a culmiation of 800+ enterprise size projects.
--------------------------------------------------------
1 line of code equals many bugs. So don't write any!!
My mad coder blog
|
|
|
|
|
I'm not quite sure how i would go about populating a class via reflection with a datareader. Can you explain/give an example please?
I didn't know VS had class generators. What are these and how do i access them?
Thanks.
|
|
|
|
|
Send me an email to n_i_c_k_5_4_5_4 _at_ hot_mail ( minus the underscores of course )
I have a forum app ( hate php and we needed a forums webite for my world of warcraft guild ) that I did in c# thats easy to understand without too many tricks. It has forums and private mail enabled. If you send an email I can give you a password to it.
Send me an email and I'll send you the project and we can discuss what and how I did it. It doesn't use any ADO calls inside the pages.
-- theories --
But, as far as the DAL and BLL.
The class exists in the BLL.
The DAL will return a populated class.
But, this also depends on who you talk to also.
I come from a Java and C++ background and move towards SOA. So I don't believe in any ADO.NET calls anywhere but the DAL.
But, people that stem from VB or other scripting languages will use ADO.NET calls anywhere ( the UI, BLL, and DAL ) and think it's proper.
But, by definition it says that the business layer does not know about the source of the data. So if you do not know the source of data, then how could you use ADO? That is tied directly to the data.
One solution I have seen before is the create a class that extends the IDBConnection and what not. But, this is just a hack to disobey the rules of abstracting the data source which a DAL implies.
And also, since the DAL could be hitting xml, oracle, sql, excel, text files, and other sources I believe the DAL should query the data and based on the class requested populate what data it can. This way the BLL is never concerned with how it got there, it just knows its there. Which is the definition of an n-tiered application.
If you send me an email, I can write a small prototype demonstrating what I am trying to infer. And add a visio document that visually shows what I'm talking about. Tell me if you have visio in the email. If not the can paste the picture into a word document.
Hope this didnt confuse you.
Nick
-- modified at 10:49 Monday 31st July, 2006
--------------------------------------------------------
1 line of code equals many bugs. So don't write any!!
My mad coder blog
|
|
|
|
|
Hi, thanks, i have just sent you an email.
|
|
|
|
|
Hi all,
I have an asp.net page that has two panels of which one is not visible. The panel that is not visible is an Ajax:DynamicPanel. I want to display this dynamicpanel on the click of an imageButton but without the postback. Is this possible? I'm also new to Ajax and I thought I can do this with Ajax. Need suggestions.
Thanks
VJ
|
|
|
|
|
make it an anchor.
set the href to #null
and put script inside the onClick event
Nick
--------------------------------------------------------
1 line of code equals many bugs. So don't write any!!
My mad coder blog
|
|
|
|
|
You could just use an asp:image and it put it in some element with a javascript OnClick event.
|
|
|
|
|
i've transfered a sql server database from win2k to winXP. It is working fine with the SQL Query analyzer and the Enterprise Manager. But in the asp.net pages it is displayig the error when i fill the sqldataadapter:
Exception Details: System.Data.SqlClient.SqlException: SQL Server does not exist or access denied.
It was working fine with the win2k. Please help!
Thanks in advance
|
|
|
|
|
Only a server operating system will let you use integrated windows security across a network. Is that your problem?
how vital enterprise application are for proactive organizations leveraging collective synergy to think outside the box and formulate their key objectives into a win-win game plan with a quality-driven approach that focuses on empowering key players to drive-up their core competencies and increase expectations with an all-around initiative to drive up the bottom-line. But of course, that's all a "high level" overview of things
--thedailywtf 3/21/06
|
|
|
|
|
i've installed sql server 2000 on winXP sp2 prof. The SQL server is working properly.
|
|
|
|
|
Are you using integrated windows security?
XP is not a server operating system and therefore you probably can't use integrated security unless you are on the server itself.
-- modified at 13:28 Friday 28th July, 2006
how vital enterprise application are for proactive organizations leveraging collective synergy to think outside the box and formulate their key objectives into a win-win game plan with a quality-driven approach that focuses on empowering key players to drive-up their core competencies and increase expectations with an all-around initiative to drive up the bottom-line. But of course, that's all a "high level" overview of things
--thedailywtf 3/21/06
|
|
|
|
|
sorry i don't know what is integrated security. You mean firewall? I'm using mcafee firewall.
|
|
|
|
|
Are you using the sql server LogIn and password are using the windows account for security?
how vital enterprise application are for proactive organizations leveraging collective synergy to think outside the box and formulate their key objectives into a win-win game plan with a quality-driven approach that focuses on empowering key players to drive-up their core competencies and increase expectations with an all-around initiative to drive up the bottom-line. But of course, that's all a "high level" overview of things
--thedailywtf 3/21/06
|
|
|
|
|
i'm using sql server login & password
|
|
|
|
|
I've installed SQL Critical Update Kit 3.0
Now i can access sql server using asp.net
Thanks
|
|
|
|
|
Your server name is incorrect. and or your password.
Create a test form and add a data source. Use the IDE to log on to it. Then grab the connection from there.
Its always easiest to let the environment create it for you first.
If you have VS2003 its even easier. Use Server Explorer. Find your table and drag it onto the form. It creates the entire connection object for you. Just open up the code and copy and paste.
Nick
--------------------------------------------------------
1 line of code equals many bugs. So don't write any!!
My mad coder blog
|
|
|
|
|
i'm using VS2003. I tried your method, it displays the following error.
Login failed for user COMP\ASPNET'.
-- modified at 13:40 Friday 28th July, 2006
|
|
|
|
|
Did you try dragging the table onto the form?
If so, then that means you need to allow the ASPNET user to query your database
I would use a different user tho
--------------------------------------------------------
1 line of code equals many bugs. So don't write any!!
My mad coder blog
|
|
|
|
|
I dragged the table. and write the following code in the page_load event
Dim ds As New DataSet
SqlDataAdapter1.Fill(ds)
Response.Write(ds.Tables(0).Rows(0).Item(0))
is that correct? Pls help. i'm confused
|
|
|
|
|
I've installed SQL Critical Update Kit 3.0
Now i can access sql server using asp.net
Thanks
|
|
|
|
|
cool.
But, going forward heres what I do if I'm unsure of the logins and server paths
I drag a stored procedure into the web form.
This will create 2 objects ( command and connection ) which you can see below the form.
The go into the code behind and inside the initialize created by the ID is your connection object. Just copy staht string and paste it into your web.config file.
You can also just view its properties in the designer.
Thats one of the tricks they taught in vb 6 and all that.
Nick
--------------------------------------------------------
1 line of code equals many bugs. So don't write any!!
My mad coder blog
|
|
|
|
|
hai
ihave a datagrid with two columns and i added itemtemplate to them as result i got the two columns as: first with all labels and second with all textboxes . ok
as
col1 col2
xxx xxx
xxx xxx
col1 as all labels and col2 all as textboxes ok
but now is there any possibility to get in the second column as
1 row as button
2 row as textbox
3 row as label etc.
inthe second column of the grid
like i want to know if there is any template row in .net if not?
how to get this?
i think u got my point
plz any body help.....
|
|
|
|