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.

 All Forums
 Development Tools
 ASP.NET
 Basic .NET Knowledge Question

Author  Topic 

X002548
Not Just a Number

15586 Posts

Posted - 2007-04-18 : 15:11:59
OK, I've always dealt with Java developers

Now I have to support a .NET Developer and I have a basic question

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

All I know is that in Java, I give those guys a rewsult set, they spin through it, and they map the data to their fields

Why can't this guy do this?

Rudy (R937) mentions something about that you can bind to a .NET table variable

What is this

Can anyone shed some light on the best practice of handling data in .NET?

http://www.dbforums.com/showthread.php?t=989246&page=483



Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Add 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 Kizer
http://weblogs.sqlteam.com/tarad/
Go to Top of Page

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.

- Jeff
http://weblogs.sqlteam.com/JeffS
Go to Top of Page

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 sprocs


CREATE 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 OUTPUT
AS

DECLARE @location varchar(20)
, @addr1 varchar(60)
, @city varchar(25)
, @state varchar(2)
, @pilrec int
, @function varchar(3)

SET NOCOUNT ON
BEGIN TRAN
DECLARE @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 BL
INNER JOIN SLIM32PROD47..LEASED L
ON BL.PROPID=L.PROPID
AND BL.BLDGID=L.BLDGID
INNER JOIN SLIM32PROD47..BLDGSPAC B
ON L.BLDGID=B.BLDGID
AND L.ID=B.ID
WHERE B.RECID = @bsrecid

IF @error <> 0 BEGIN
SELECT @Error_Loc = 3, @Error_Type = 50001, @rc = -1
GOTO MEPPILFormGen_Err END

IF @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 END

IF @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 function

SELECT @pilrec = PILRECID FROM PIL WHERE BSRECID = @bsrecid
IF @pilrec IS NOT NULL
BEGIN
SET @function = 'UPD'
END
ELSE
BEGIN
SET @function = 'NEW'
END


IF @function = 'NEW'
BEGIN

EXEC MEPTEXTCONVERT 'PIL', @bsrecid


UPDATE PILTEMP2
SET STAFF1 = 0,STAFF2 = 0,STAFF3 = 0,STAFF4 = 0,STAFF5 = 0
,STAFF6 = 0,STAFF7 = 0,STAFF8 = 0,STAFF9 = 0
WHERE RECID = @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,
'' as CREComments,
-- Change * to be all the columns in the PILTEMP2 table

*
FROM PILTEMP2 WHERE RECID = @bsrecid



END /* 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 = @bsrecid

END /* END UPDATE */


COMMIT TRAN
MEPPILFormGen_Exit:
SET @e = GetDate()
EXEC [usp_LogProcCalls]
'MEPPILFormGen' , @s, @e, @APPUSER, @rowcount, @error, ' ', @sprc OUTPUT
SET NOCOUNT OFF
Return
MEPPILFormGen_Err:
ROLLBACK TRAN
RAISERROR @Error_Type @Error_Message
GOTO MEPPILFormGen_Exit

GO



Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Add yourself!
http://www.frappr.com/sqlteam



Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2007-04-18 : 16:14:19
And as far as bs...it may be, but I think it's more that they don't know .NET all that well


Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Add yourself!
http://www.frappr.com/sqlteam



Go to Top of Page

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.

- Jeff
http://weblogs.sqlteam.com/JeffS
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2007-04-18 : 16:58:02
Well I might try that..

Does this make any sense

Grid view and Form Control?

That's what he was doing to start, or at least that's what he said

I'm going to meet with the 2 debvelopers tomorrow and see what they are doing



Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Add yourself!
http://www.frappr.com/sqlteam



Go to Top of Page

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 1980
blog: http://weblogs.sqlteam.com/mladenp
Go to Top of Page

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.

- Jeff
http://weblogs.sqlteam.com/JeffS
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2007-04-19 : 09:29:34
It's a web application.

Usually I deal with Java developers and WebSphere...

I get a feeling that there's a lot of smoke being blowing

http://www.amazon.com/Selected-Shorts-Dan-Hicks-Licks/dp/B00031TXWC



Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Add yourself!
http://www.frappr.com/sqlteam



Go to Top of Page

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.aspx
Learn SQL
http://www.sql-tutorial.net/
http://www.firstsql.com/tutor.htm
http://www.w3schools.com/sql/default.asp
Go to Top of Page

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.net
Data 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.aspx
Creating a data access layer (great for scalability and maintainability): http://msdn2.microsoft.com/en-us/library/aa581780.aspx
Using parameterized Queries (avoid SQL injection attacks!): http://www.4guysfromrolla.com/webtech/092601-1.shtml

That should get him started on the right track...

HTH,

-Andrew

Go to Top of Page
   

- Advertisement -