Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
X002548
Not Just a Number
15586 Posts |
Posted - 2007-04-18 : 15:11:59
|
OK, I've always dealt with Java developersNow I have to support a .NET Developer and I have a basic questionThe Guy is telling me that he is/was using objects called datagrid or form something...and to use those he created a mess of a sproc with cursors, permanent "temp" tables to denormalize the data so he could use these objectsAll I know is that in Java, I give those guys a rewsult set, they spin through it, and they map the data to their fieldsWhy can't this guy do this?Rudy (R937) mentions something about that you can bind to a .NET table variableWhat is thisCan anyone shed some light on the best practice of handling data in .NET?http://www.dbforums.com/showthread.php?t=989246&page=483Brett8-)Hint: Want your questions answered fast? Follow the direction in this linkhttp://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspxAdd yourself!http://www.frappr.com/sqlteam |
|
tkizer
Almighty SQL Goddess
38200 Posts |
Posted - 2007-04-18 : 15:25:14
|
quote: The Guy is telling me that he is/was using objects called datagrid or form something...and to use those he created a mess of a sproc with cursors, permanent "temp" tables to denormalize the data so he could use these objects
He's trying to sell you BS.Most of the developers that I support use .NET. We don't have a single cursor in any of our sprocs and we don't need to denormalize the data with permanent temp tables.Tara Kizerhttp://weblogs.sqlteam.com/tarad/ |
|
|
jsmith8858
Dr. Cross Join
7423 Posts |
Posted - 2007-04-18 : 15:29:03
|
A DataGrid just binds an HTML table to any datasource, which is often the result of a stored procedure. It adds more features as well from a UI perspective, but that's the jist of it. Updates, Deletes and all that still use regular SQL statements or stored procedures to get the job done ... a DataGrid in no way forces or encourages developers to write stored procedures with cursors and temp tables.If this person is writing T-SQL code like that and you can see that simple JOINS and such will suffice from a database perspective, then they probably simply don't know how to write good SQL. Maybe a quick training session with them will suffice, if you go through one of their stored procs with them one on one and give them some tips showing how to write it better. And, of course, direct them to SQLTeam.- Jeffhttp://weblogs.sqlteam.com/JeffS |
|
|
X002548
Not Just a Number
15586 Posts |
Posted - 2007-04-18 : 16:06:30
|
Well I put an end to their sproc writing days yesterday after I saw this..I added some error handling and sproc logging...but for the most part I didn't want to touch it, or impact deliverable dates...since this is just the start, I'm leaving this...going forward, I'm writing the sprocsCREATE procedure MEPPILFormGen @bsrecid int , @detached int , @Leaseid char(8) , @BG char(8) , @SUBBG char(15) , @Expdt char(10) , @APPUSER char(30), @rc int OUTPUT, @error int OUTPUT, @rowcount int OUTPUTASDECLARE @location varchar(20) , @addr1 varchar(60) , @city varchar(25) , @state varchar(2) , @pilrec int , @function varchar(3)SET NOCOUNT ONBEGIN TRANDECLARE @s datetime, @e datetime, @Error_Message varchar(255), @Error_Type int, @Error_Loc int, @sprc int SELECT @rc = 0, @s = GetDate()IF EXISTS(SELECT * FROM PILTEMP2 WHERE RECID = @bsrecid) BEGIN DELETE FROM PILTEMP2 WHERE RECID = @bsrecid SELECT @error = @@ERROR, @rowcount = @@ROWCOUNT IF @error <> 0 BEGIN SELECT @Error_Loc = 1, @Error_Type = 50001, @rc = -1 GOTO MEPPILFormGen_Err END IF @rowcount = 0 BEGIN SELECT @Error_Loc = 2, @Error_Type = 50002, @rc = 1 , @Error_Message = 'Staging Table Not Cleared out for ID: ' + CONVERT(varchar(10),@bsrecid) GOTO MEPPILFormGen_Err END END-- Get location name SELECT @location = CASE WHEN @detached = 0 THEN BL.NAME ELSE 'Detached - ' + SUBSTRING(L.NAME,4,5) END , @addr1=BL.ADDR1 , @city=BL.CITY , @state=BL.ST FROM SLIM32PROD47..BUILDING BLINNER JOIN SLIM32PROD47..LEASED L ON BL.PROPID=L.PROPID AND BL.BLDGID=L.BLDGIDINNER JOIN SLIM32PROD47..BLDGSPAC B ON L.BLDGID=B.BLDGID AND L.ID=B.ID WHERE B.RECID = @bsrecidIF @error <> 0 BEGIN SELECT @Error_Loc = 3, @Error_Type = 50001, @rc = -1 GOTO MEPPILFormGen_Err ENDIF @rowcount = 0 BEGIN SELECT @Error_Loc = 4, @Error_Type = 50002, @rc = 1 , @Error_Message = 'No Rows SELECTED For ID: ' + CONVERT(varchar(10),@bsrecid) GOTO MEPPILFormGen_Err ENDIF @rowcount > 1 BEGIN SELECT @Error_Loc = 5, @Error_Type = 50002, @rc = 3 , @Error_Message = 'More than 1 Row SELECTED For ID: ' + CONVERT(varchar(10),@bsrecid) GOTO MEPPILFormGen_Err END-- Check for functionSELECT @pilrec = PILRECID FROM PIL WHERE BSRECID = @bsrecidIF @pilrec IS NOT NULLBEGIN SET @function = 'UPD'ENDELSE BEGIN SET @function = 'NEW'ENDIF @function = 'NEW'BEGINEXEC MEPTEXTCONVERT 'PIL', @bsrecidUPDATE PILTEMP2 SET STAFF1 = 0,STAFF2 = 0,STAFF3 = 0,STAFF4 = 0,STAFF5 = 0,STAFF6 = 0,STAFF7 = 0,STAFF8 = 0,STAFF9 = 0 WHERE RECID = @bsrecidIF @detached = '0' BEGIN UPDATE PILTEMP2 SET PANEL1VISIBLE = 'True', PANEL2VISIBLE = 'False', PARAGRAPH0 = REPLACE(PARAGRAPH0,'XXX',@Expdt) WHERE RECID = @bsrecid END ELSE BEGIN UPDATE PILTEMP2 SET PANEL1VISIBLE = 'False', PANEL2VISIBLE = 'True', PARAGRAPH0 = REPLACE(PARAGRAPH0,'XXX',@Expdt) WHERE RECID = @bsrecid END SELECT @location as Location, @state as State, @city as City, @addr1 as Addr1, @Leaseid as LeaseId, @BG as BG, @SUBBG as SUBBG, @Expdt as Expdt, '' as CREComments, -- Change * to be all the columns in the PILTEMP2 table * FROM PILTEMP2 WHERE RECID = @bsrecidEND /* END NEW */ELSE /* UPDATE */BEGIN EXEC MEPTEXTCONVERT1 'PIL', @pilrec, @bsrecid EXEC MEPSTAFFCONVERT1 'PIL', @pilrec, @bsrecid IF @detached = '0' BEGIN UPDATE PILTEMP2 SET PANEL1VISIBLE = 'True', PANEL2VISIBLE = 'False', PARAGRAPH0 = REPLACE(PARAGRAPH0,'XXX',@Expdt) WHERE RECID = @bsrecid END ELSE BEGIN UPDATE PILTEMP2 SET PANEL1VISIBLE = 'False', PANEL2VISIBLE = 'True', PARAGRAPH0 = REPLACE(PARAGRAPH0,'XXX',@Expdt) WHERE RECID = @bsrecid END SELECT @location as Location, @state as State, @city as City, @addr1 as Addr1, @Leaseid as LeaseId, @BG as BG, @SUBBG as SUBBG, @Expdt as Expdt, P.CREComments, -- Change * to be all the columns in the PILTEMP2 table * FROM PILTEMP2 P2 JOIN PIL P ON P2.RECID = P.BSRECID WHERE RECID = @bsrecidEND /* END UPDATE */COMMIT TRANMEPPILFormGen_Exit:SET @e = GetDate()EXEC [usp_LogProcCalls] 'MEPPILFormGen' , @s, @e, @APPUSER, @rowcount, @error, ' ', @sprc OUTPUTSET NOCOUNT OFFReturnMEPPILFormGen_Err:ROLLBACK TRANRAISERROR @Error_Type @Error_MessageGOTO MEPPILFormGen_ExitGO Brett8-)Hint: Want your questions answered fast? Follow the direction in this linkhttp://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspxAdd yourself!http://www.frappr.com/sqlteam |
|
|
X002548
Not Just a Number
15586 Posts |
|
jsmith8858
Dr. Cross Join
7423 Posts |
Posted - 2007-04-18 : 16:35:22
|
As I mentioned, I don't think knowledge of .NET is the issue here, it is knowledge of SQL. If I were his DBA, I'd take a few minutes to at least let the guy walk me through his code so I could see what he is thinking, and then give I'd try to him some general pointers and tips to see if he can learn a few things and write cleaner SQL. My goal would be to help him improve his SQL skills so that we both could benefit .... Only if that didn't work and he didn't respond well to it would I consider more drastic actions such as writing his stored procedures for him, which in the short run might sound like a good idea but in the long run means lots more work for both of you and he never ends up learning anything and comes to rely on you to do his work for him.That's just me, though .... I recognize that I am kind of an oddball here in the corporate world as someone who values communication.- Jeffhttp://weblogs.sqlteam.com/JeffS |
|
|
X002548
Not Just a Number
15586 Posts |
|
spirit1
Cybernetic Yak Master
11752 Posts |
Posted - 2007-04-19 : 03:50:08
|
just wondering... is it a desktop application or a web application?_______________________________________________Causing trouble since 1980blog: http://weblogs.sqlteam.com/mladenp |
|
|
jsmith8858
Dr. Cross Join
7423 Posts |
Posted - 2007-04-19 : 08:38:48
|
yes, that's my question too ... traditionally the words "form" and "control" imply a desktop windows app, but they also use that terminology in .net web applications as well. What confuses me is this: usually, when you see bad SQL code written by a developer, it is usually because a wizard is generating that code. But the SQL you have shown definitely wasn't generated, it was clearly written, so I don't think anyone can use .NET as an excuse for writing poor SQL in this particular case.- Jeffhttp://weblogs.sqlteam.com/JeffS |
|
|
X002548
Not Just a Number
15586 Posts |
|
DonAtWork
Master Smack Fu Yak Hacker
2167 Posts |
Posted - 2007-04-19 : 11:59:19
|
Yep. They are selling you a load of bull. If they are using VS2005, They are totally full of it. You can return a simple result set, and they can shove that into a dataset, an array, a generic, or any number of other objects and play with the data.[Signature]For fast help, follow this link:http://weblogs.sqlteam.com/brettk/archive/2005/05/25.aspxLearn SQLhttp://www.sql-tutorial.net/ http://www.firstsql.com/tutor.htm http://www.w3schools.com/sql/default.asp |
|
|
ACushen
Starting Member
29 Posts |
Posted - 2007-04-26 : 13:50:41
|
Not to mention the fact that in ASP.NET 2.0 (which is what's being used if he's using a GridView), a GridView or FormView can be bound to a DataSource, which in turn gets its data from an SPROC, all without a single line of ASP.NET code! (Obviously you will have to code the SPROC first.)Sounds to me like this guy just doesn't know ASP.NET *or* T-SQL very well. There is ***absolutely*** nothing in ASP.NET that requires either cursors(shudder!) or permanent temp tables. You give me an SPROC that returns data from a SELECT, and I'll have the data on a web page in 2 minutes flat, without a single line of code. (Of course, to make the site scalable, maintainable, etc. will take more work, but...)BTW, yes, GridViews and FormViews are legitimate ways to put data on a page in ASP.NET...I'm with Jeff on this one, either send the guy to a basic T-SQL course or have someone teach him some basics...unfortunately, it sounds like he needs some help with data access in ASP.NET, also. Have him look around on almost *any* ASP.NET website, they will show him much better ways of handling data! Here are some links:*The* ASP.NET page: http://www.asp.netData access in ASP.NET: http://www.asp.net/learn/dataaccess/Accessing and Updating Data in ASP.NET 2.0: Accessing Database Data:http://aspnet.4guysfromrolla.com/articles/022206-1.aspxCreating a data access layer (great for scalability and maintainability): http://msdn2.microsoft.com/en-us/library/aa581780.aspxUsing parameterized Queries (avoid SQL injection attacks!): http://www.4guysfromrolla.com/webtech/092601-1.shtmlThat should get him started on the right track...HTH,-Andrew |
|
|
|
|
|
|
|