Groups | Blog | Home
all groups > sql server (microsoft) > february 2007 >

sql server (microsoft) : C# SQL interface


Jon Slaughter
2/22/2007 2:29:54 AM
I'm writing essentially a client based SQL interface(although the client
accesses it indirectly).

In the database there will be several different types of tables. Initially
I was only going to use one table structure but I felt that it would be more
productive to have it arbitrary.

Now I want to generate an gui for access each table. The issue here is that
each is structured differently.

So maybe I have one table that has {Name, ID, Info} and another {Hash, ID}
and I want to automatically generate a gui for this. I was thinking that I
could make an xml file that basically copies this structure and generate the
interface(Which is essentially just lables and text boxes) for the user to
interact with. But I was thinking this is unnecessary? Can't I just get
the table structure directly from SQL and generate the xml files? (or bypass
that all together... although I wouldn't want to query the database every
time when the structure will rarely change except when adding new tables).

e.g., I could create a new windows form interface for each table when I add
it. This would require me to design and rebuild the application every time a
table is changed. I could use XML that "mimic" the table structure and then
write the generic code in the app but this would require me to write the XML
code each type(which isn't so bad and doesn't require recompliation but has
sync/versioning issues). But I could get the table structure directly from
the database and generate the interface "on the fly" and it would work
arbitrarily for any table. The main issue here is that I would be wasting a
lot of processing power and bandwidth for doing the same task over and over.
So I suppose I could cache the table structure info or something like that.

Anyways, Is there any better way to handle this?

Thanks,
Jon

John Berberich
2/22/2007 7:56:04 PM
[quoted text, click to view]

Jon,

Have you considered dumping your data into a System.Data.DataSet and
binding it to a System.Windows.Forms.DataGridView?

- John
Jon Slaughter
2/23/2007 4:31:28 AM

[quoted text, click to view]

I'd like to have a better looking interface but I suppose that might be a
possible solution. I'd like to get away from the "tables" look if possible
but I suppose it does offer a consistant approach without much work.

A slight issue is that the application will not be directly interfacing with
the database for security reasons. I suppose this isn't a real issue though
as I'm sure it could be worked around.

Thanks,
Jon

mangist NO[at]SPAM gmail.com
2/23/2007 8:08:37 PM
On Feb 22, 11:31 pm, "Jon Slaughter" <Jon_Slaugh...@Hotmail.com>
[quoted text, click to view]

I have implemented something similar to what you are achieving. What
you should do is use a control to bind to the BindingContext to allow
navigation of records easily (i.e. a button next/previous/first/last
and a textbox to type an ID). After this, loop through the columns
in the DataTable and programmatically add labels to the form under
each other with the .Text property set to the column name (add a space
in place of capitol letters (i.e. PostalAddress becomes Postal
Address). Then add a Windows.Forms.Control based on what the DataType
of the DataColumn is. I supported text (TextBox), bool (CheckBox),
Date (DateTimePicker) etc. Then programatically bind each of these
controls to the fields in your DataSet.

Get the idea?

Not incredibly hard to implement, try using the TableLayoutPanel to
help with adding controls to a form dynamically.

Hope this helps,
AddThis Social Bookmark Button