|
|
Comments and Discussions
|
|
 |

|
Please take Care of mismatch in C# keywords and Column names in tables. For example in my case one of the column names is "abstract" and when models were generated it created a property with this name and thereby conflict.
but nevertheless a good work.
Zubair Masoodi
Software Engineer
SmartBuzz Solutions Chandigarh
Email: Zubairmasoodi@gmail.com
www.smartbuzz.com
|
|
|
|

|
Thanks a lot..
Gr8 work!!
=============
NITIN SAWANT
=============
|
|
|
|

|
Uh, doesn't SQL Mangement Studio already do this? Not only can you create the table with a propper user interface you can then generate the code used to generate the table.
|
|
|
|

|
Do not hit 'reply' to this email: To reply, click here.
Derek Bartram has posted a new comment at "Article "Introduction to Object Oriented Programming Concepts (OOP) and More"":
This article was taken from a book.... see link
http://www.rsdn.ru/Forum/message/2917569.1.aspx[^]
________________________________________________________________
That book is taken it from me
What is that all about anyway..
Yes, SQL support this now, but it was not there by the time I thought/ write this.. Now I wanted to delete it but CP does not support deleting it.
- A random opportunity is like a tall chair, those who sit hang on, those who hang on fall
L.W.C. Nirosh.
Colombo,
Sri Lanka.
|
|
|
|

|
Nirosh wrote: That book is taken it from me
What is that all about anyway..
Appologies, I had removed it anyway though. Looked very much like an article someone I know had posted.
Nirosh wrote: Yes, SQL support this now, but it was not there by the time I thought/ write this.. Now I wanted to delete it but CP does not support deleting it.
Give them an email I guess
|
|
|
|

|
Derek Bartram wrote: Looked very much like
I doubt it!! Can I see that article??
Derek Bartram wrote:
Give them an email I guess
Yes, I will check that with Chris, but as I know these days they are very busy
- A random opportunity is like a tall chair, those who sit hang on, those who hang on fall
L.W.C. Nirosh.
Colombo,
Sri Lanka.
modified on Saturday, May 3, 2008 11:33 AM
|
|
|
|

|
Nirosh wrote: I doubt it!! Can I see that article??
Sadly I can't as it's an internal document. It was just the writing style and subject mostly though. Anyways, my bad, sorry.
Nirosh wrote: Yes, I will check that with Chris, but as I know these days they are very busy
Isn't he just, i'm waiting on an email from him myself.
|
|
|
|

|
I am not able to create Class Files as i am getting this error while running the application "cannot find Stored Procedure "getDate""
vidushi Tandon
|
|
|
|

|
SP is given in the article ..
This is a quick help: Open the query analyser or management studio for the DB you are trying to generate the code for.. and paste the below
CREATE PROCEDURE getData AS
select table_name, column_name, data_type
from information_schema.columns
where table_name in
(
select table_name
from Information_Schema.Tables
where Table_Type='Base Table'
) order by table_name
GO
That will create the SP for you..
L.W.C. Nirosh.
Colombo,
Sri Lanka.
|
|
|
|

|
i create the procedure in the pubs database,
and i run the program using pubs, sa, and my ip in the textbox.
But nothing happens, or error prompt!
|
|
|
|

|
I am not getting you..
do you mean to say that you ran it in a system database?
Can you please create a new database and run this.. same time make sure that the SQL DB is allow remote connection and your machine firewall is off mode..
- A random opportunity is like a taller chair, those who sit hang on, those who hang on fall
L.W.C. Nirosh.
Colombo,
Sri Lanka.
|
|
|
|

|
Hi, I am sorry to tell you this, but your code send shivers down my spine.
Take this as a "code review", a positive criticism - and let me assure that your code does what it is supposed to do - it just has a lot of space for improvements.
I am just doing this to warn other coders, specially the new ones, that several things here are not good coding practice.
Things like string.Format("...", new object[] { ... });
First of all, you don't need the new object[]; just put the objects, like this:
string.Format("{0} {1} {2}", new object[] { string1, Customer.Name, 3 });
Second thing: the scape character for curly brackets in string.Format format argument is {{ for a { and }} for a }, like this:
"\r\n\tpublic {0} {2}\r\n\t{{ \r\n\t\tget {{ return _{1}; }}\r\n\t\tset {{ _{1} = value; }}\r\n\t}}\r\n
I think this is a start. Ahh, one more thing, try to put Microsoft.ApplicationBlocks.Data.dll in you source code zip file; If someone does not have Application Blocks installed, it doesnt run.
Or don't use it at all, doing something like this (notice that I dont need to create a stored proc with this):
SqlCommand cmd = new SqlCommand();
cmd.Connection = connection;
cmd.CommandType = CommandType.Text;
cmd.CommandText = "select table_name, column_name, data_type from information_schema.columns where table_name in ( select table_name from Information_Schema.Tables where Table_Type='Base Table' ) order by table_name";
SqlDataReader dr = cmd.ExecuteReader();
I know that the CommandText could be better formatted, but I will let this as is.
Finally, I would like to thank you, your code saved me some precious minutes. Was a good start for what I needed.
HunterKiller
|
|
|
|

|
Luciano Bargmann wrote: I am sorry to tell you this, but your code send shivers down my spine.
I am sorry about it
Luciano Bargmann wrote: Take this as a "code review", a positive criticism
You are most welcome, even if it is not constructive..
First of all, you don't need the new object[]; just put the objects, like this:
string.Format("{0} {1} {2}", new object[] { string1, Customer.Name, 3 });
I am not getting you, once you say you don't need the object[], but still you do use it..
Anyway.. the whole idea of this codie is not to show the best coding practise..
I was leading a project and we ran out of people at the middle of the project and I had to alone code the whole application server part of the project, while four other people were coding at the web site (front end).. It was bearly impossible to kept my phase up to support requests coming from all four people at the same time, so I spent some two days writting this.. I posted it here as it is.. so you are correct this is not the best code show..
Finaly it is glad to hear that it helps you
L.W.C. Nirosh.
Colombo,
Sri Lanka.
|
|
|
|

|
First of all, you don't need the new object[]; just put the objects, like this:
string.Format("{0} {1} {2}", new object[] { string1, Customer.Name, 3 });
I am not getting you, once you say you don't need the object[], but still you do use it..
OMG! I should review MY code before reviewing others!
You are right, my example should be
string.Format("{0} {1} {2}", string1, Customer.Name, 3);
So.. you had lots of fun in this project, huh? :->
Cheers, HunterKiller
|
|
|
|

|
First I want to say that you did a very nice job.
Thank you for code sample.
Second the last class file doesn't get saved properly.
The problem is that the following lines are missing in the end of the loop before the done message:
} // end of loop
// bug fix ...
if (sw != null)
{
this.CreateClassBottom(sw, sb.ToString().TrimEnd(new char[ { ',', ' ', '\r', '\t', '\n' }), sbAttr.ToString());
sw.Close();
}
MessageBox.Show("Done !!");
|
|
|
|

|
Hi,
Thank you for the point.. I will look in to this.. and will do a update asap..
Thanks again,
Nirosh.
L.W.C. Nirosh.
Colombo,
Sri Lanka.
|
|
|
|

|
In the CreateModelClassFiles() method, the following code from the "else" section should be copied into the "if (lstrOldTableName != lstrTableName)" section after the new file is created: this.CreateClassBody(sw, lstrAttributeType, lstrAttributeName); sb.AppendFormat("{0} {1}, \r\n\t\t", new object[] { lstrAttributeType, lstrAttributeName }); sbAttr.AppendFormat("\r\n\t\tthis._{0} = {0};", new object[] { lstrAttributeName }); This ensures the 1st field of the table read from the database is included in the class file. Otherwise, this is a handy tool--minor tweeks to get running in VS 2005.
|
|
|
|

|
Thanks for the point, I will do an update ASAP.
Thanks Again,
L.W.C. Nirosh.
Colombo,
Sri Lanka.
|
|
|
|

|
Does the getData stored procedure work against any DBMS, or is it tailored to some specific DBMS?
Also, have you by chance (I haven't, yet) found a way to get the list of tables, or, even better, the DB schema from *any* DBMS, without using a stored procedure?
I've been tinkering around with something like you describe in this article,
and your work looks like a good start for a more complete solution.
For instance,
I'd consider making your code generator add a constructor for the generated class that takes a DataRow as a parameter. I usually end up writing that sort of constructor in my business-tier classes so that my data-access layer can do stuff like
foreach(DataRow dr in myDataSet)
{
myBusinessClass myObject = new myBusinessClass(dr);
myCollection.Add(myObject);
}
(Assuming myDataSet is a DataSet and you have some sort of collection myCollection).
Thanks,
F.O.R.
|
|
|
|

|
One of my 1st ventures into c# was a code/class generator. A sample can be found online at http://gfwcsharp.yyyz.net/- it works and I use it often. The generated code doesn't use stored procedures, just c# and standard sql calls.
To get a list of tables, try something like this...
// ////////////////////////////////////////////////////////////////////////
///
/// Get a list of the Database Tables based on the connection
/// It returns user tables only
///
public static DataTable GetUserTables()
{
string Query = " SELECT Name, Id FROM sysobjects "
+ " WHERE type='U' AND Name <> 'dtproperties' "
+ " ORDER BY Name ";
DataTable Dt = null;
SqlConnection m_SqlConnection = new SqlConnection(CGfwCSharp.DbConnectionSQL);
SqlDataAdapter m_SqlDataAdapter= new SqlDataAdapter(Query,m_SqlConnection);
try
{
Dt = new DataTable();
m_SqlDataAdapter.Fill(Dt);
}
catch
{
Dt = null;
}
finally
{
m_SqlDataAdapter.Dispose();
m_SqlConnection.Close();
}
return Dt;
}
and to get the columns, something like this...
// ////////////////////////////////////////////////////////////////////////
///
/// Query to get the Columns in the selected table
/// Called by GetTable_Click() below
///
/// string with SQL Query
public static DataTable GetTableColumns(string TableName) // Get the columns
{
string Query = " select syscolumns.name as 'column', "
+ " systypes.name as 'type', "
+ " syscolumns.length as 'length', "
+ " syscolumns.isnullable as 'isnullable', "
+ " syscolumns.autoval as 'isAuto' "
+ " from syscolumns inner join systypes "
+ " on syscolumns.xtype = systypes.xtype and"
+ " syscolumns.xusertype = systypes.xusertype "
+ " where syscolumns.id = "
+ TableName // Selected Table Name
+ " and systypes.name <> 'sysname' "
+ " order by syscolumns.colid ";
DataTable Dt = null;
SqlConnection m_SqlConnection = new SqlConnection(CGfwCSharp.DbConnectionSQL);
SqlDataAdapter m_SqlDataAdapter= new SqlDataAdapter(Query,m_SqlConnection);
try
{ Dt = new DataTable();
m_SqlDataAdapter.Fill(Dt);
Dt.Columns.Add(new DataColumn("Auto",typeof(bool)));
int Count=Dt.Rows.Count;
if(Count>0)
{
for (int i=0;ihttp://gfw.yyyz.net/HtmShow.aspx?WA=1
Hope this helps.
|
|
|
|

|
Yes this article is a good one and it does have addressed some of my next steps.. but not all.. so keep in touch... again this is also not for all databases.. but the question is all about getting the table list from *any* DBMS. Do you have any other link that do some what similar things...
Thanks for the time
Regards,
Nirosh.
L.W.C. Nirosh,
Software Engineer,
TextCENTRIC Technology,
Colombo,
Sri Lanka.
|
|
|
|

|
Hi Frank,
What a thinker.. yes.. I will get to what u need.. but my immediate solution going to be for MS SQL. I just thow this article to see the user review and I was really impressed with your post. My immediate solution going to be building a class set (automatically) that can do all the basic db manupulations. such as if I take the Asset table the basic table handling going to be... Add a asset object to the table, Delete a Asset object from the table, Select a Asset object from the table.. next it is going to add more variety to select and update section.. the handler going to have method to select all the attributes.. given the ID.. and it is going to have update method for all the attribute given the ID.. but obviuosly the data mining is not this simple and in your application may need to obay some condition when updating and may need to have more options when selecting... what ever these additional parts .. user has to write manually..
This will continue to a next level as well... but for the moment it will only be for .Net/C# with MS SQL. But your interest will for sure gave me teh strenght to go for all DB solution as well..
Thanks for ur time
Nirosh.
L.W.C. Nirosh,
Software Engineer,
TextCENTRIC Technology,
Colombo,
Sri Lanka.
|
|
|
|
 |
|
|
General News Suggestion Question Bug Answer Joke Rant Admin
|
This will create a set of classes that generate a set of C# class files which map into the database tables. They will have the class name same as the table name and they will have a set of properties that are same as the table attributes.
| Type | Article |
| Licence | CPOL |
| First Posted | 11 Nov 2004 |
| Views | 98,062 |
| Bookmarked | 76 times |
|
|