|
Subject:
|
Dataset
|
|
Posted By:
|
vgsgowrisankar
|
Post Date:
|
4/15/2008 10:51:43 PM
|
hai sir, in cs.net application i am using dataset sir . for example there is 5 forms . shall i use separate dataset for each and every winforms or shall i create the library and there shall i create the dataset and connect the library with my application and use that single dataset for all my forms. because i feel complicated to create the relations between datatables if i use library.
thank you sir
|
|
Reply By:
|
robzyc
|
Reply Date:
|
4/16/2008 2:16:48 AM
|
Hi there.
It depends on what you are doing really. You have not given us much of an overview of the scenario. However, using a single DataSet does have significant advantages since it does a lot of the maintenence leg-work for you when working with relational data.
If its too complicated, then learn how to do it  If you have a strict deadline that does not offer the time to learn how to do it, talk to your manager/lead developer, its an important decision and you need to know how to make itm and its down to your superiors to get you up to speed. If you dont want to learn how to do it, I think you may be in the wrong industry 
A lot of the creation of the DataSet can actually be done for you by using the wizards in VS.
Rob The Developing Developer Currently Working Towards: MCAD C# My Blog: http://robzyc.spaces.live.com
|
|
Reply By:
|
vgsgowrisankar
|
Reply Date:
|
4/16/2008 8:36:32 AM
|
hello sir, i am not saying about to try . i said coding logic is complex if i use library . so please encourge me. dont discourge me. thank you
|
|
Reply By:
|
abhishekkashyap27
|
Reply Date:
|
4/16/2008 9:14:11 AM
|
So dont use library if you are feeling uneasy in doing so, since you are going to use 5 forms only, use separate dataset for every form, name it like dsForm1,dsForm2...,etc..,
Well if you have time, then dont hesitate to experiment with some new ideas. :)
-- Abhishek
|
|
Reply By:
|
samjudson
|
Reply Date:
|
4/16/2008 9:17:40 AM
|
We are not trying to discourage you, but we are finding it hard to understand what you mean.
If you are trying to display the exact same data on 5 very similar forms then having a class that does that work for you and returns 'the same' dataset each time will work much better than writing the code 5 times in 5 different forms.
Is that what you meant?
/- Sam Judson : Wrox Technical Editor -/
|
|
Reply By:
|
robzyc
|
Reply Date:
|
4/16/2008 9:25:46 AM
|
There are a number of design implications to using different DataSets for each form, one of the most important is maintainability.
DataSets are weakly-typed (i.e. everything is stored as Object). You can overcome this by generating a strongly-typed DataSet based on the current data model. However, if ANY of this changes, then you need to update your generated DataSet.
I dont understand how the "coding logic is complex", since you gave no idea as to how your applcation is built, but I am pretty sure ANY developer will agree with me that "if the logic is 'too complicated' to change", then there is something wrong with the logic. Code needs to be maintainable, and a large part of that is the ability for it to change and evolve. If that means ripping the guts out of a part of it, then it may be required. If not, and your superiors give you heat, explain the situation to them. If they still say "we need it done" then comment everything and hack away. 
Like I said before, you can create a DataSet using the wizard, that will handle the creation of the DataRelation objects required to maintain your data. If you do not understand relational data.. Then.. Wow.. Have a chat with your boss and get them to explain it to you?
Rob http://robzyc.spaces.live.com
|
|
Reply By:
|
vgsgowrisankar
|
Reply Date:
|
4/16/2008 1:17:30 PM
|
Sir i clearly exaplain to you, public static DataSet GlobalExecute(string sp,string dt) { if (scon.State == ConnectionState.Closed) { scon.Open(); } SqlDataAdapter sda = new SqlDataAdapter(sp, scon); DataSet ds = new DataSet(); sda.Fill(ds, dt); sda.Dispose(); return (ds);
} sir i am using this code to execute the process. i send the stored procedure name and datatbale name to this function. this function will execute from here sir. for example : i call this function like this in my form sir.
string send_sp ="exec sp_insrec 'E101','jones', 700000"; Dataset ds =new Dataset(); ds= lib.GlobalExecute(send_sp,t1);
then i use this dataset [ds] in my form sir. we can execute the stored procedure in 2 methoths
1. we give stored procedure name and parmaters.add(@,Sqltype,textbox....)
2. string send_sp ="exec sp_insrec 'E101','jones', 700000"; like this .
if i use first method i want to send the stored procedure name and how many parameters i am using , parameters data type, from which field the data will send everything.
if use second one . directly i send the string . in that string everthing will be send ie, stored procedure name , and parameters values . then it will execute simply.
pls provide the suggestion which method is best and why ? thank you sir
|
|
Reply By:
|
samjudson
|
Reply Date:
|
4/16/2008 2:58:54 PM
|
The former is always better, because it avoid many of the inherent errors involved with SQL injection security issues.
However it is slightly more complex to code obviously.
/- Sam Judson : Wrox Technical Editor -/
|
|
Reply By:
|
robzyc
|
Reply Date:
|
4/16/2008 3:47:27 PM
|
Sam is right, the StProc method is definately the way to go, its more efficient and secure.
As for getting the DataView up and running, you are passing the name of the desired table (string dt) to your GlobalExecute method. You can add some extra code where required to hook up a DataView to that table.
So, instantiate your DataSet, get a reference to the table (ds.Tables[string name]), instantiate a DataView based on the DataTable, job done! 
Rob http://robzyc.spaces.live.com
|
|
Reply By:
|
vgsgowrisankar
|
Reply Date:
|
4/16/2008 11:49:03 PM
|
thank you so your solution is exec sp_insrec 'E101','jones', 700000 is correct . is it ?
|
|
Reply By:
|
robzyc
|
Reply Date:
|
4/17/2008 12:20:00 AM
|
Well, like Sam and I said, it will work, but it is not preferable since ideally, SqlParameters should be used rather than passing strings about.
What you have will work though 
Rob http://robzyc.spaces.live.com
|