Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / March 2008

Tip: Looking for answers? Try searching our database.

display View output in DataGridView

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
viepia@nospam.com - 09 Mar 2008 02:13 GMT
Hi,
  How do I go from a text file containing:

CREATE VIEW MyView
AS
SELECT *  FROM  MyTable

where my VS2008 LINQ application knows the database MyView is targeting ==> to  a
DataGridView.DataSource?  The database had dozens of tables; my application needs to
handle any VIEW possible; in use there will be hundreds of these text file VIEWs.
I don't want to do any more parsing of the text files than necessary.

One way I thought to do this is to install the VIEW selected by the user is by ALTER
VIEWing a fixed name VIEW already installed on SQL Server 2005.  My application would have
a fixed name UDF dragged onto the DBML referencing the fixed name VIEW; the UDF is set as
the DataSource for a DataGridView   The problem with this is the early binding done by the
MSLinqToSQLGenerator when an UDF is dragged to the DBML: XML in the DBML file and C# code
in MyDatabaseClasses.designer.cs that sees through the UDF and the View to the underlying
MyTable.    Even though there is no change in its code ALTER FUNCTION also has to be run
for the UDF.    For this to work I need to find out to dynamically delete/drag the UDF
from/to the DBML or find some other way to force an equivalent action, maybe by using the
MSLinqToSQLGenerator in runtime; ALTER VIEW and ALTER FUNCTION are easy with
SqlCommand.ExecuteNonQuery.    I can dynamically refresh the DataGridView by setting
DataGridView.DataSource to null, then reattaching the UDF, then Refresh, DoEvents (or
maybe Refresh, DoEvents are all that is necessary, I can't know until I know how to
dynamically  delete/drag the UDF).  

Thanks,
Viepia
Marc Gravell - 09 Mar 2008 09:28 GMT
> One way I thought to do this is to install the VIEW selected by the user is by ALTER
> VIEWing a fixed name VIEW already installed on SQL Server 2005.
Changing one already installed would be very confusing (not to mention
"thread race"), and hard frmo a security perspective. It would be
better to create a temporary view for the user - or lose the "VIEW"
completely and just use the SELECT. But this isn't really LINQ -
you're juts talking raw commands now

> the UDF is set as the DataSource for a DataGridView.
As you've found - this isn't going to work. LINQ (and other ORM tools)
demand the schema is well known.

Basically, you can't use LINQ for this. I recommend just SqlCommand
and the SELECT, since the VIEW and UDF aren't helping you at all. This
might be one of the rare occasions when I suggest a DataTable as the
data-store. I'm not a fan of DataTable, but it might do the job nicely
here...

Marc
viepia@nospam.com - 09 Mar 2008 13:16 GMT
Using a DataTable made it easy, thanks very much.
Viepia

>> One way I thought to do this is to install the VIEW selected by the user is by ALTER
>> VIEWing a fixed name VIEW already installed on SQL Server 2005.
[quoted text clipped - 15 lines]
>
>Marc

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.