Javascript must be enabled in your browser to use this page.
Please enable Javascript under your Tools menu in your browser.
Once javascript is enabled Click here to go back to سیستم عامل جدید ایرانیان v2.88
A Visual SQL Query Designer

situation in the site

صقحه اصلی Articles DataBase A Visual SQL Query Designer

Search

Statistics Site

mod_vvisit_countermod_vvisit_countermod_vvisit_countermod_vvisit_countermod_vvisit_countermod_vvisit_counter
mod_vvisit_counterامروز24
mod_vvisit_counterدیروز120
mod_vvisit_counterاین هفته299
mod_vvisit_counterاین ماه1224
mod_vvisit_counterکل بازدیدها39858

Online users

We have 1 guest and 2 members online

Members of the online

Banner
Banner

اخبار ايران

With law enforcement to targeted subsidies were no poor country will not
With law enforcement to targeted subsidies were no poor country will not
تهران - رييسجمهوري با اشاره به اهميت اجراي قانون هدفمند کردن يارانه ها تاکيد کرد : با اجراي اين قانون هيچ فقيري در کشور باقي نمي ماند. Tehran - President pointed out the importance of law enforcement targeted subsidies emphasized: with the implementation of the law of any country remain poor.
به گزارش خبرنگار سياسي ايرنا ،محمود احمدينژاد که روز سه شنبه در ديدار با شرکتکنندگان بيست و يکمين همايش ملي معرفي کارگران و گروههاي کار نمونه کشور سخن ميگفت،افزود :اجراي اين قانون 100 درصد به نفع جامعه کارگري است . According to IRNA political correspondent, Mahmoud Ahmadinejad on Tuesday to meet with participants in the Twenty-first National Conference workers and group work to introduce the country spoke instance, added: "Implementation of this law 100 percent in favor of workers.
وي در بخش ديگري از سخنان خود افزود: بايد مناسبات کاري خود را با فرهنگ کشورمان منطبق کنيم زيرا نميتوان با فرهنگ سرمايهداري و مادي غرب مناسبات کاري کشور را تنظيم کرد. He added that another part of his speech: To be working with our culture because we can not comply with the material culture of the capitalist West relations and the country set to work. کارفرمايان بايد با کارگران براساس فرهنگ کشور خودمان برخورد کنند و در اين امر از کشورهاي غربي الگو نگيرند. Employers should treat workers according to their own country and culture in Western countries, this pattern other users.
احمدينژاد ادامه داد: ماموريت همه ما ساختن ايران است که البته همه هياهوها، اظهارنظرها و حرکتها بايد معطوف به ساختن ايران باشد. Ahmadinejad continued: our mission to make all of the constitutional revolution, of course, the comments should be focused on building the movement in Iran. هر اقدامي که در جهت ساختن ايران نباشد فايدهاي ندارد. Any action to make Iran does not Faydhay.
رييس دولت دهم اولين لازمه ساختن ايران را همدلي دانست و بيان کرد: براي ساختن ايران نيازمند همدلي هستيم که همدلي جامعه کارگري الگويي براي همه اقشار است زيرا اگر به اين موضوع توجه شود، همه کارها با سرعت بيشتري انجام خواهد شد. I needed to make the first head of government of Iran expressed sympathy and said: Iran needs to build empathy empathy that are a model for all strata of society workers because if this is the subject of attention, everything will be done more quickly.
رييسجمهوري در ادامه با تاکيد بر اينکه ما نيازمند نگاه به افقهاي بلندي در کار هستيم، تصريح کرد: ارزيابيها به ما نشان ميدهد ظرفيت پيشرفت در کشور ما سه برابر وضع فعلي است. More President emphasized that we need to look at long horizons we work, emphasized: "Our evaluations show that the capacity to progress in our country is three times the current situation. اگرچه در سالهاي اخير پيشرفت کشور رشد قابل توجهي داشته است اما باز هم ظرفيت کار زيادي در کشور وجود دارد. Although the country's progress in recent years has had significant growth but still a lot of work capacity in countries.
وي افزود: يکي از محورهاي اساسي نظام سلطه براي تسلط بر ملتها، جلوگيري از همدلي آنها است و براي از بين بردن همدلي ميان اعضاي يک خانواده سرمايهگذاري و تلاش بسياري ميکنند. He added: "One of the main axes system of domination for domination over nations, to prevent them sympathy and empathy for the destruction of the members of a family investment and effort are many.
احمدينژاد از نگاه به قلههاي بلند به عنوان دومين لازمه ساختن ايران ياد کرد و خاطرنشان کرد: اگر ملتي همدلي و امکانات داشته باشد اما افقهاي بلندي را وجهه همت خود قرار ندهد، پيشرفت نخواهد کرد. Ahmadinejad to look up as the second peak of construction required to learn and noted: "If a nation is possible, but empathy and long horizons does not face their efforts, progress will not. زيرا افقهاي بلند، همتهاي بلند را برميانگيزاند. Horizons because the long, long Brmyangyzand Hmthay.
وي با تاکيد بر اينکه افق نگاه ملت ما،جهاني است،تصريح کرد: ملتي در دستيابي به اهدافش موفقتر است که بالاترين قلههاي جهاني را مورد نظر خود قرار دهد. He emphasized that looking at the horizon of our nation, world, emphasized: "the most successful nation in achieving its goals is the highest peak in the world are looking to. حتي کساني هستند که افق نگاهشان ساختن جامعه بشري است. Their eyes lock, even those who make the horizon of human society. مطمئنا اين افراد بهتر ميتوانند کشور خود را بسازند. Surely these people can better their own country. بنابراين هرچقدر افقهاي ما بلندتر باشد، همت ما قويتر، مستحکمتر و عميقتر خواهد بود. So no matter how our horizons are longer, our efforts stronger, deeper and stronger will.
احمدي نژاد کار، تلاش و پيگيري را ديگر عامل ساختن ايران دانست و گفت: بسياري از افراد افقهاي بلندي دارند اما اهل کار و تلاش نيستند درحالي که براي رسيدن به افقهاي بلند بايد همت بسيار و کار و تلاش پيدرپي داشت. Ahmadinejad's work, effort and other factors make up the Iran and said: Many people have horizons loudness but not from work and while trying to reach a long horizons should be much effort and work to Pydrpy found.
رييس دولت دهم با بيان اينکه جامعه کارگري در سه بخش همدلي، نگاه بلند و کار و تلاش پيشتاز و پيشگام است، تصريح کرد: در طول دوره انقلاب جامعه کارگري ما در همدلي ممتاز بوده است، بهطوري که در برههاي از زمان گروههاي وابسته به استکبار تلاش کردند در جامعه کارگري فاصله و اختلاف ايجاد کنند اما اين قشر از جامعه همواره به آنها پاسخ منفي و محکم داد. Head of government do with the expression of sympathy workers in three parts, looked up and work to express and Pioneer has emphasized: "During the Revolution of Our workers have been privileged in sympathy, so much so that the lambs from the time-dependent groups of arrogance community workers tried to create distance between segments of society, but they always gave a strong negative response.
احمدينژاد جامعه کارگري را از منسجمترين اقشاري دانست که در جهت خدمت و پيشرفت کشور فعاليت ميکنند و خاطرنشان کرد: جامعه کارگري در همه عرصههاي انقلاب در خط مقدم حرکت کرده است که اوج اين حرکت را در دوران هشت سال دفاع مقدس ديديم. Ahmadinejad Mnsjmtryn strata of society, workers knew that serve and advance the country working and noted: community workers in all fields of revolution has been at the forefront of moves that during the peak of this movement we saw eight years of sacred defense. بسياري از افراد جامعه کارگري به عنوان نيروي داوطلب به جبهه اعزام ميشدند. Many people labor community as volunteers were dispatched to the front. در بخش کار و تلاش هم اين قشر يک لحظه دست از کار و تلاش برنداشته است. In both segments of work to hand in a moment of work and effort has not taken.
وي با اشاره به اينکه بخش مهمي از پيشرفتهاي صنعتي و اقتصادي کشور ما مرهون جامعه کارگري است،بيان کرد: از همه کارگراني که با ابتکار و نوآوري خود موجب شدند هزينههاي بسياري در کشور کاهش يابد تشکر ميکنم و البته اين موفقيت از ايمان، تعهد، پاکي و دلسوزي جامعه کارگري برميآيد. He pointed out that an important part of industrial and economic progress of our country owes the community workers, stated: "all workers with initiative and innovation led to reduced costs in many countries and of course I thank the success of faith, commitment, Worker falls innocence and caring society.
رييسجمهوري درباره مسووليت دولت براي استفاده از ظرفيت کار در کشور خاطرنشان کرد: دولت بايد مقدمات استفاده از اين ظرفيت را فراهم کند. President about government responsibility for the use of labor capacity in the country noted: the primary use of this capacity should provide. همچنين پشتيبانيهاي لازم را انجام دهد که البته بخش عظيمي از اين مسووليت متوجه توليدکنندگان و خدماتدهندگان اعم از کارفرمايان و کارگران است. Pshtybanyhay also necessary to do that of course much of this responsibility and the producers noticed Khdmatdhndgan both employers and workers.
رييس دولت دهم خطاب به کارفرمايان تصريح کرد: همه ما براي ساختن ايران يک خانواده هستيم و با اعتقادات و فرهنگ کشور خود زندهايم. Head of State addressed to employers, I emphasized: "All of us are used to build a family of beliefs and cultures and their countries survive. در فرهنگ ما رسيدگي به حال کارگر بالاترين عبادت و موجب برکت کار است که اين موضوع را دنياي سرمايهداري درک نميکند. In our culture now working to address the highest blessing prayer and led the work on this issue does not understand the capitalist world. بنابراين با توجه به جامعه کارگري بايد موجب برکت شويد. Therefore, workers should lead society bless you.
احمدينژاد افزود: ما در دولت برکت را به خوبي ديدهايم. Ahmadinejad added: "We have seen the blessing as well. به عنوان مثال دولت در سال 88 حقوق کارمندان را 22 درصد، حقوق نيروهاي نظامي و انتظامي را 26 درصد و حقوق بازنشستگان را افزايش داد. For example, in the 88 to 22 percent of workers rights, rights of military and police and 26 percent pension increase. همچنين بخش قابل توجهي از بدهيهاي دولت به سازمان تامين اجتماعي را هم پرداخت کرد. Also, a significant portion of government debt to social security organization also paid. کارهاي عمراني بسياري هم انجام داد، يارانهها را هم کم نکرد اما هنگامي که تفاوت هزينه دولت در سال 88 را نسبت به سال 87 بررسي ميکنيم متوجه ميشويم خرج دولت تنها 2 درصد افزايش يافته است. Many also did construction work, too little subsidies but the difference did not cost the government 88 years than 87 years, we realize we will investigate government spending has increased only 2 percent. اين موضوع نشاندهنده برکت در کار دولت است. This work shows the blessing of government.
وي با انتقاد از کساني که بر شعار "دو بچه کافي است " تاکيد ميکردند، گفت: کساني هستند که فکر ميکنند ذخاير عالم به دست آنهاست، بنابراين از اينکه کسي سه بچه يا بيشتر داشته باشد ناراحت ميشوند و براي مردم قانون ميگذارند و ميگويند حق نداريد سه بچه داشته باشيد. He criticized those on the slogan "Two children are enough" would emphasize, he said: those who think the world of resources available to them, so that one or more children is Tuesday are upset and called for the law and put right Tuesday do not have kids.
رييسجمهور خطاب به اين افراد اظهار کرد: روزي فرزند را خداوند ميدهد. President addressed to the people remarked: One day the child of God. بنابراين اين شعار قابل قبول نيست. Thus, this slogan is not acceptable. حتي آنها موضوع فقر را براي اين شعار مطرح کردند اما خداوند در قرآن ميفرمايد: "از ترس فقر بچههاي خود را نکشيد، ما به آنها با شما روزي ميدهيم." Poverty issue even those raised for this slogan, but the Holy Qur'an states: "their children for fear of poverty, eg, we provided you give them."
احمدينژاد به مقايسه وضعيت مردم در سال 60 با سال 89 پرداخت و خاطرنشان کرد: در سال 60 در روستاها آب، برق و مخابرات نبود و در شهرها هم مردم با چند کوپن زندگي خود را ميگذراندند اما با اينکه امروز جمعيت 75 ميليون نفر يعني دوبرابر شده، وضع مردم بهتر شده است، بهطوري که ميزان دانشجويان کشور 10 برابر شده ، صنعت، کشاورزي و اختراع رشد قابل توجهي داشته است و بيمارستان و مدرسه ساخته شده.بنابراين رشد جمعيت موجب فقر مردم نشده است. Ahmadinejad compared the situation in 60 years with 89 years of payments and noted: in 60 rural water, electricity and telecommunications were also people in cities and a few coupons, but spent his life today that the 75 million population doubled , the situation has improved, so much so that the students of the country by 10 times, industry, agriculture and the invention has considerable growth and built hospitals and schools. Thus, population growth causes poverty, not people.
وي با اشاره به اجراي سياستهاي کنترلي جمعيت از سوي کشورهاي غربي بيان کرد: کشورهاي غربي سياستهايي را براي کنترل جمعيت خود اعمال کردند اما امروز رشد آنها منفي شده است. He pointed out the population control policies expressed by the Western countries: Western countries policies to control its population growth imposed, but today they are negative. بهطوري که از کشورهاي ديگر افراد را براي زندگي به کشور خود ميبرند که اين کار موجب از بين رفتن آن ملت خواهد شد. So much so that people from other countries for life to his country intended that this caused the loss of the nation will be.
رييس دولت دهم با اعلام اينکه جمعيت خانوار در کشور به زير چهار نفر رسيده است، تصريح کرد: تعداد بچههاي يک خانواده در کشور کمتر از دو نفر شده است، اين موجب سقوط يک ملت خواهد شد. Head of Government announced that the tenth of households in the country has been under four, asserted: the number of children in a family has less than two, this will cause the fall of a nation. متاسفانه کساني که شعار کنترل جمعيت را سرميدادند به نتيجه برعکس آن رسيدند. Unfortunately, those who control the slogan Srmydadnd population reached its contrary conclusion. زيرا امروز شاهد آن هستيم که مردم فقير فرزندان بيشتري دارند اما کساني که از امکانات خوبي برخوردارند فرزند کمتر دارند. Because today we are seeing that poor children have more opportunities for those who have a child less good.
رييسجمهوري در بخش ديگري از سخنان خود با تاکيد بر به روز کردن سيستمها و امکانات کار در کشور، خاطرنشان کرد: بايد با مديريت درست از هزينههاي اضافي کم کرد و البته سيستمها را بهروز کرد. President in another part of his speech with an emphasis on updating systems and facilities to work in the country, noted: it must properly manage the additional costs low, and of course, to update systems. همچنين بايد براي ابتکار عمل کارگران پاداشي تعيين شود. You should also reward the workers for the initiative to be determined.
احمدينژاد خطاب به کارگران گفت: در هر کجاي کشور که کار ميکنيد، به ثروت عمومي ملت ايران توجه داشته باشيد. Ahmadinejad addressed the workers said: "anywhere in the country you work, the general wealth of nations note. اگر بازدهي کار شما بالا باشد ميزان اين ثروت عمومي هم افزايش خواهد يافت. If your work is high level of efficiency this will increase the public wealth. بنابراين تا روزي که کار ميکنيد متعهد و دلسوز باشيد. So until the day you work you are committed and compassionate.
وي همچنين خطاب به وزير کار و امور اجتماعي ،اذعان کرد: فضاي کار کشور را به گونهاي اداره کنيد تا اختلافي پيدا نشود. He also addressed to the Minister of Labor and Social Affairs, acknowledged: the country's working environment can somehow manage to not be disputed. شما مامور انجام عدالت هستيد اما عدالت را طوري اجرا کنيد که به سمت جامعه کارگري برود. Your agent do you justice, but justice run so that the community workers go.
رييسجمهوري با انتقاد از فعاليت شرکتهاي ثالث براي تامين نيروي کار تصريح کرد: بايد نقش شرکتهاي ثالث در رابطه ميان کارگر و کارفرما از ميان برود تا منافع بيشتري به کارگران برسد. President criticized the activities of third party companies to provide workforce emphasized: should the role of third-party companies in the relationship between workers and employers eliminating benefits to reach more workers. البته ما چندينبار در دولت براي حل اين مشکل مصوباتي را ابلاغ کرديم اما بسياري از افراد از عملياتي شدن آن جلوگيري کردند. Of course, we Chndynbar government to solve this problem we have delivered Msvbaty but many people were prevented from its operations. البته با پيگيريهايي که انجام شد نشان داده که به غير از بخش حملونقل و فضاي سبز، بقيه بخشهاي دولت نقش شرکتهاي ثالث را براي تامين نيروي کار حذف کردند. Pygyryhayy course that was shown that except for transportation and green space sector, other government departments as third-party companies to provide workforce eliminated.
رييس دولت دهم با اشاره به اقدامات دولت براي حل مشکل بيمه کارگران ساختماني بيان کرد: اقدامات لازم براي حل اين مشکل انجام شده و به زودي وزير رفاه اين موضوع را ابلاغ خواهد کرد. I pointed to the head of government measures to solve the problem of building insurance, workers said: measures necessary to solve this problem done soon and welfare minister will deliver on this issue.
احمدينژاد همچنين بر پيگيري اختصاص سهام عدالت به کارگران تاکيد کرد و گفت: اين موضوع را پيگيري ميکنيم و حتما به نتيجه ميرسانيم. Ahmadinejad also follow up on the shares allocated to workers emphasized justice and said: "We followed up this issue and certainly the result of writing.
وي همچنين گفت: به بنياد نخبگان سفارش ميکنم که براي پذيرفتن ابداعات و اختراعات کارگران با مماشات بيشتري برخورد کند. He also said: "Foundation for the elite order that I accept the innovations and inventions workers to deal with the more appeasement.
سيام**9144**9170 Siam ** 9144 ** 9170

ليگ برتر

Head of the assessment exercise capital derby
"Ali Said Loo" the head of the Physical Education Organization said that "I hope worthy team won the derby capital in the current week."
Sixty right capital derby on Wednesday this week between the two most popular team independence and Perispolis will be held.
The game week in the framework of twenty-sixth premier league Soccer Iran clubs will be held.
The head of the Physical Education Organization on Monday in an interview with IRNA sports reporter also said: "I hope with observance of moral points and technical, every team that can be more appropriate in this meeting is to win.
سعیدلو said: the people of Iran Football to a good and I hope massrs 60 righth righth derby to echelon capital popular with spectators and more appropriate team to three points of the game of it.
He pointed out that in some cases sensitivity and characteristics of a special meeting, managers, technical staff and players to play cautiously and is the subject, to some extent the beauty of the soccer decreases.
The head of the sport of the country said: "I hope in this game, Susceptivity s by the yearneth.
Said Loo stressed that the president of the football federation and two club and Perispolis independence have said that people understand football. By maintaining fair play and observance of moral dimensional on technical issues to focus in the end of this game proud.
8071

At the end news/Islamic Republic news agency (IRNA)/news code 930038
A Visual SQL Query Designer PDF Print E-mail
Written by مدیر کل سایت   
Thursday, 18 February 2010 15:26
There are no translations available.

Query Designer

Introduction

This article describes the implementation of a QueryDesignerDialog class that allows users to create SQL queries based on a given OLEDB connection string.

The designer is similar to the ones found in database tools such as the SQL Server Management Studio and Microsoft Access. It allows end users to build SQL queries with support for sorting, grouping, and filtering.

The main limitation of the QueryDesignerDialog is that it does not parse existing SQL statements. This is a one-way tool; you can use it to create new queries, but not to edit existing ones. Also, it only supports OLEDB data sources, which includes SQL Server and Access. Future versions may address these limitations.

Background

The first version of the QueryDesignerDialog was written for use with a Report Designer application. I could not find a tool (free or commercial) to do the job the way I wanted, so I decided to write it myself. After that, I re-used it in a few other applications, and thought it might be useful to others as well.

Using the Code

The QueryDesignerDialog has two main properties:

  • ConnectionString: Gets or sets the OLEDB connection string used to retrieve the database schema with the list of tables, views, fields, and relations from which the query will be built.
  • SelectStatement: Gets the SQL statement designed by the user. For now, this is a read-only property. The dialog cannot be used to edit existing SQL statements. Perhaps this will be added in future versions.

The code snippet below shows how the QueryDesignerDialog is typically used. You assign it a connection string, show the dialog, and read back the SQL query:

Collapse
// create the QueryDesignerDialog
using (var dlg = new QueryDesignerDialog())
{
// set the connection string

dlg.ConnectionString = ConnectionString;
// show the dialog

if (dlg.ShowDialog(this) == DialogResult.OK)
{
// get the new Sql query and do something with it

string newSql = dlg.SelectStatement;
DoSomething(newSql); }
}

Implementation

The QueryDesignerDialog relies on two important helper classes:

  • OleDbSchema: This class extends the ADO.NET DataSet class. It takes an OLEDB connection string and fills the DataSet with all the tables, views, columns, relations, and constraints defined in the database (it does not retrieve any data). Applications can then expose these elements in a visual UI to preview the data, create and edit queries, and so on. The OleDbSchema class also provides utility methods for checking table types, encoding their names with brackets when necessary, managing Stored Procedure parameters, and so on.
  • QueryBuilder: This class uses the OleDbSchema class, and maintains a list of query fields with properties that define sorting, grouping, etc. It is also responsible for building SQL statements based on the query fields and on the database schema.

Selecting a Connection String

In order to use the QueryDesignerDialog, you need an OLEDB connection string. Some applications may use a list of pre-defined connection strings, others allow the user to create the connection string at run time. The sample included with this article falls in the second category.

The OleDbConnString class included in the code provides utilities for dealing with connection strings. The main methods in that class areGetConnectionString and EditConnectionString, both of which show the DataLinks dialog used to create or edit connection strings:

Collapse
string newConnString = OleDbConnString.GetConnectionString(this);
string editConnString = OleDbConnString.EditConnectionString(this, editConnString);

These methods rely on the following system assemblies which must be referenced by the project:

  • OLEDB32.dll: Contains the DataLinks class (which used to be in MSDASC.DLL). This file can be found at C:\Program Files\Common Files\System\Ole DB\OLEDB32.DLL.
  • ADODB.dll: This is required to read the COM object passed back from DataLinks. This file can be found at C:\Program Files\Microsoft.NET\Primary Interop Assemblies\ADODB.DLL.

Once the user has picked a connection string, most applications will save it in a list for later re-use. Because the connection strings tend to be quite long, showing them to users may be challenging, so the OleDbConnString class provides a TrimConnectionString method that shortens the connection strings for display purposes, keeping only the provider and data source parts. The sample application provided with the article uses TrimConnectionStringto display recently used connection strings in an owner-drawn combobox.

Retrieving the Database Schema

When you assign a connection string to a QueryDesignerDialog, it starts by retrieving the database schema so it can show the user a list of the tables and views available for use in the query. This job is done by the OleDbSchema class mentioned above. The code looks like this:

Collapse
// get schema for the new connection string
OleDbSchema schema = OleDbSchema.GetSchema(connectionString);

The OleDbSchema class extends the ADO.NET DataSet class. You can use it to enumerate the elements available in the database, including tables, views, Stored Procedures, fields, relations, and constraints. If the connection string is invalid, or if some error occurs while getting the schema, then GetSchemareturns null.

Some of the information retrieved from the database is stored in the ExtendedProperties property of the tables and fields. For example, views and Stored Procedures in the database are represented by DataTable objects, and can be identified by their ExtendedProperties[TABLE_TYPE] value. TheOleDbSchema class provides helper methods that deal with this, so callers don't have to. For example, the GetTableType method returns a value that indicates whether a DataTable in an OleDbSchema represents a regular table, a view, or a Stored Procedure.

The implementation of the OleDbSchema class is based on the OleDbConnection.GetOleDbSchemaTable method. This method allows you to retrieve tables, views, Stored Procedures, relations, and constraints defined for the connection. Once you have a table, the OleDbDataAdapter.FillSchemamethod is used to retrieve the fields. If you are interested in the details, please refer to the source code.

The example below shows how the QueryDesignerDialog class populates a TreeView control with the tables and views available in the database:

Collapse
// update table tree to reflect new connection string
void UpdateTableTree()
{
// initialize table tree

TreeNodeCollection nodes = _treeTables.Nodes;
nodes.Clear();
var ndTables = new TreeNode(Properties.Resources.Tables, 0, 0);

var ndViews = new TreeNode(Properties.Resources.Views, 1, 1);

// populate using current schema

if (Schema != null)
{
// populate the tree
_treeTables.BeginUpdate();
foreach (DataTable dt in Schema.Tables)
{
// create new node, save table in tag property

var node = new TreeNode(dt.TableName);
node.Tag = dt;
// add new node to appropriate parent

switch (OleDbSchema.GetTableType(dt))
{
case TableType.Table:

ndTables.Nodes.Add(node);

node.ImageIndex = node.SelectedImageIndex = 0;
AddDataColumns(node, dt);
break;
case TableType.View:
ndViews.Nodes.Add(node);
node.ImageIndex = node.SelectedImageIndex = 1;
AddDataColumns(node, dt);
break;
}
}
// add non-empty nodes to tree

foreach (TreeNode nd in new TreeNode[] { ndTables, ndViews })
{
if (nd.Nodes.Count > 0)

{

nd.Text = string.Format("{0} ({1})", nd.Text, nd.Nodes.Count);
nodes.Add(nd);
} }
// expand tables node
ndTables.Expand();
// done

_treeTables.EndUpdate();
} }
void AddDataColumns(TreeNode node, DataTable dt)
{
foreach (DataColumn col in dt.Columns)

{
var field = node.Nodes.Add(col.ColumnName);

field.Tag = col;
2;
field.ImageIndex
=
field.SelectedImageIndex = 2;

}

}

The OleDbSchema class is used internally by the QueryDesignerDialog class, but it is public, and can also be used directly by applications that need access to schemas. The sample application included with the article uses it to populate a list with all the tables, views, and Stored Procedures in the database.

Building SQL Queries

Once the database schema is available, we can use it to build queries. This is done by the QueryBuilder class, which maintains a list of QueryFieldobjects and generates SQL statements. The main properties of the QueryBuilder class are:

  • ConnectionString: Used to retrieve the database schema. The schema defines the tables and fields used in the query, and also the relations between the tables which are needed to build the SQL JOIN statements.
  • QueryFields: A collection of QueryField objects used to build the query. Each QueryField object represents a database field or an expression, and has properties that define sorting, grouping, aliasing, and so on. This is a bindable collection suitable for display in a DataGridView control, for example.
  • Sql: The SQL Select statement built to represent the current state of the QueryFields collection.

The Sql property is read-only. It builds the SQL query in parts, based on the QueryFields collection.

First, the SELECT clause is built by scanning the fields and outputting the proper table/view and column names. Next, the QueryFields collection is analyzed to determine how the tables are connected. This allows the QueryBuilder to create the FROM clause with the required JOIN statements, which is by far the most complicated and interesting part of the class. Finally, the ORDER BY and WHERE clauses are built based on the properties of the QueryField objects.

To build the FROM clause of the SQL statement, the QueryBuilder class starts by building a list of tables so that each table on the list is related to the next one. This is accomplished by the InsertRelatedTable method. Next, it scans the list to find the relation that connects each table with the following one. Each relation is then used to build the corresponding JOIN statement.

The QueryField class contains the information that defines each field in the query. It has the following properties:

  • Column: The string that specifies the name of a column within a table (e.g., "FirstName") or an expression (e.g., "LEFT(FirstName, 2)").
  • Alias: Optional string used to identify the field instead of the Column value. If provided, this value is used as the column name on the query results table. For example, if the Column property is set to "LEFT(FirstName, 1)" and the Alias property is set to "FirstInitial", the output table will contain a column named "FirstInitial".
  • Table: String that identifies the table that contains the column. This property is read-only; it is provided only for binding purposes (so the table names appear on the field grid described later).
  • Output: Boolean value that determines whether the field should be included in the output table. This is used to hide fields that are needed to define the query but should not appear in the output (e.g., fields used in calculations or to provide connections between related tables).
  • GroupBy: Aggregate to use when grouping the field. This column is used only if the QueryBuilder.GroupBy property is set to true. In this case, the original data records are grouped and represented by an aggregate such as a sum or average. For example, to create a query showing the average product price per category, you would use two fields: "CategoryName", with GroupBy set to GroupBy; and "ProductPrice", with GroupBy set to Average.
  • Sort: Specifies whether the field should be used to sort the output in ascending or descending order.
  • Filter: A filter expression used to select the records included in the output. If provided, the expression should be of the format [OPERATOR] [VALUE] or BETWEEN [VALUE1] AND [VALUE2]. To reduce the possibility of syntax errors when specifying the Filter value, the QueryDesignerDialog class provides an editor for this property instead of allowing users to type the expressions directly.

Designing SQL Queries

The QueryDesignerDialog class provides the user interface for creating queries. It uses the QueryBuilder class described above, and adds the following UI elements:

  • Table/View tree: This is a TreeView control containing all the tables and views in the data source and all the fields within each table/view. Fields can be double-clicked or dragged onto the QueryField grid to be added to the query. The TreeView has a context menu that allows users to remove specific tables/views from the list or navigate to tables that are related to the one that is currently selected.
  • QueryField grid: This is a DataGridView control that shows the fields currently included in the query and their properties. Users may reorder the fields by dragging the grid rows, remove fields by deleting rows, and edit fields directly on the grid.
  • Sql view: This is a TextBox control that shows the SQL statement as the user adds and edits individual fields on the grid. The TextBox is read-only. Users can see the SQL statement and copy it to the clipboard, but they cannot change it by typing on the TextBox.
  • ToolStrip: The ToolStrip on top of the dialog contains buttons for toggling the query's GroupBy property, editing query properties, checking the SQL syntax, previewing the query results, and for clearing the query.

The Table/View tree is the element that deviates the most from the traditional query design tools available in tools such as SQL Server Management Studio and Microsoft Access. It shows all the tables by default, instead of asking users to add and remove them individually. Tables and views are shown as tree nodes, rather than as small floating lists. The tree-based UI is substantially simpler. The main drawback it has is that the connections between tables are not readily visible to the user. This is somewhat alleviated by the context menu that shows related tables on demand.

The image below shows the QueryDesignerDialog in action, creating a query against the popular AdventureWorks database:

Query Designer

QueryField Grid Implementation

The QueryField grid is a DataGridView that displays a list of QueryField objects. By default, the DataGridView uses text boxes for editing non-boolean cells and check boxes for booleans. This is not ideal for editing values that are enumerations, such as the Sort and GroupBy properties of theQueryField class. Those are much easier to edit with combo box controls instead. Also, we wanted to use a custom editor for the Filter field, which is of type string but has formatting requirements that are better handled with a custom editor.

These requirements seem very common, so I think showing the code here might be useful to some developers. The code below shows how you can replace regular DataGridView columns with combo box ones for fields that are enumerations.

Collapse
// replace regular grid columns combo box columns for enum types
void FixGridColumns()
{
for (int i = 0; i < _grid.Columns.Count; i++)

{
var col = _grid.Columns[i];

if (col.ValueType.IsEnum)

{
// create combo column for enum types

var cmb = new DataGridViewComboBoxColumn();
cmb.ValueType = col.ValueType;
cmb.Name = col.Name;
= col.DataPropertyName; cmb.HeaderText = col
cmb.DataPropertyName
.HeaderText;
layStyleForCurrentCellOnly = true;
cmb.Dis
p
cmb.DataSource = Enum.GetValues(col.ValueType);

cmb.Width = col.Width;
// replace original column with new combo column

_grid.Columns.RemoveAt(i);
_grid.Columns.Insert(i, cmb);
} }
}

The sample also replaces the "Filter" column with one that shows a button instead of a text box. Clicking the button brings up a filter editor dialog which can be used to edit the filter value. I would rather give users a choice, allowing them to type filter values directly into the cell or click a button on the right of the cell to show the editor dialog. That is in the to-do list for a future version.

Sample Application

The sample application included with this article is a dialog that allows users to select a connection string, see all the tables, views, and Stored Procedures in the corresponding database, create queries against the database, and see the corresponding data. It could be used as a data source selection tool in applications such as report designers (which is actually why this was written in the first place).

The image below shows the sample application in action:

Sample Application

The application has a ToolStrip along the top of the main dialog.

The ToolStrip contains a combobox that provides a list of recently used connection strings, and allows users to type or paste connection string values.

The dropdown part of the combobox is owner-drawn to show a trimmed version of the connections strings which are easier to read than the full version. The owner-draw code uses the TrimConnectionString method in the OleDbConnString class as shown below:

Collapse
// trim items in combo box (they're very long)
void cmb_DrawItem(object sender, DrawItemEventArgs e)
{
var fmt = new StringFormat();

fmt.LineAlignment = StringAlignment.Center;

fmt.Trimming = StringTrimming.EllipsisPath;

var text = (string)_cmbConnString.Items[e.Index];
text = OleDbConnString.TrimConnectionString(text);
var brush = (e.State & DrawItemState.Selected) != 0

? SystemBrushes.HighlightText

: SystemBrushes.WindowText;
.DrawString(text, _cm
e.DrawBackground(); e.Graphic
sbConnString.Font, brush, e.Bounds, fmt);
e.DrawFocusRectangle();
}

The list of recent connection strings is saved as an application setting so it can be reused across sessions.

The button next to the combobox allows users to create new connection strings using the familiar "DataLink" dialog. The button uses theEditConnectionString method in the OleDbConnString class as shown below:

Collapse
// pick a new connection
void _btnConnPicker_Click(object sender, EventArgs e)
{
// release mouse capture to avoid wait cursor

_toolStrip.Capture = false;
// get starting connection string

// (if empty or no provider, start with SQL source as default)
string connString = _cmbConnString.Text;
if (string.IsNullOrEmpty(connString) ||
connString.IndexOf("provider=", StringComparison.OrdinalIgnoreCase) < 0)
{
connString = "Provider=SQLOLEDB.1;";
}
// let user change it

ConnectionString = OleDbConnString.EditConnectionString(this, connString);
}

This code invokes the "DataLink" dialog seen below:

DataLinks

The next button (with a magic wand image) invokes the QueryDesignerDialog which allows users to design SQL queries. Once the query is ready, it is shown in a TextBox on the second tab of the main form. The code that invokes the QueryDesignerDialog looks like this:

Collapse
// invoke SQL builder
void _btnSqlBuilder_Click(object sender, EventArgs e)
{
using (var dlg = new QueryDesignerDialog())

{

dlg.Font = this.Font;
dlg.ConnectionString = ConnectionString;
if (dlg.ShowDialog(this) == DialogResult.OK)
{
_txtSql.Text = dlg.SelectStatement;

_tab.SelectedTab = _pgSql;

UpdateUI(); } }
}

The code creates a QueryDesignerDialog, initializes its ConnectionString property, then shows the dialog and retrieves the results by reading the dialog's SelectStatement property.

The last button (with a preview image) loads the data from the currently selected source (table, view, Stored Procedure, or SQL statement) into a DataTableand shows the table on a modal dialog. The implementation is given below:

Collapse
// preview data for currently selected node
void PreviewData()
{
// create table to load with data and display

var dt = new DataTable("Query");
// if a table/view is selected, get table name and parameters

if (_tab.SelectedTab == _pgTables)
{
// get table/view name

var table = _treeTables.SelectedNode.Tag as DataTable;
dt.TableName = table.TableName;
// get view parameters if necessary

var parms = OleDbSchema.GetTableParameters(table);
if (parms != null && parms.Count > 0)
{
var dlg = new ParametersDialog(parms);
dlg.Font = Font;
if (dlg.ShowDialog(this) != DialogResult.OK)

{
return;

}

}
}
// get data
try
{
using (var da = new OleDbDataAdapter(SelectStatement, ConnectionString))
{
// get data

da.Fill(0, MAX_PREVIEW_RECORDS, dt);
// show the data

using (var dlg = new DataPreviewDialog(dt, Font, Size))
{
dlg.ShowDialog(this);

}

}
}
catch (Exception x)
{
Warning(Properties.Resources.ErrGettingData, x.Message); }

}

The first part of the code handles the case where the TreeView page is selected. It gets the name of the table that is currently selected, and uses theParametersDialog helper class to prompt the user for any required parameters. The parameters entered by the user are stored as extended properties of the selected table.

Next, the code builds an OleDbDataAdapter to read the actual data. The parameters are given by the SelectStatement and ConnectionStringproperties. The SelectStatement is a SQL string that reflects the current user selection. It could be either the node currently selected on the TreeView, or the custom SQL generated with the QueryDesignerDialog.

This is the code that implements the SelectStatement property:

Collapse
public string SelectStatement
{
get

{

// table/view/sproc
if (_tab.SelectedTab == _pgTables)
{
var nd = _treeTables.SelectedNode;

return nd == null || nd.Tag == null || _schema == null

? string.Empty

: OleDbSchema.GetSelectStatement(nd.Tag as DataTable);

}

else // explicit sql statement
{
return _txtSql.Text;
} }
}

The implementation uses the GetSelectStatement method of the OleDbSchema class. This method returns a string that depends on the type of table passed as a parameter. If the table is a regular table or view, the method returns a Select statement. If the table represents a Stored Procedure, the method returns an exec statement including the name of the Stored Procedure and the parameter values stored as extended properties. In our case, the parameter values were set by the ParametersDialog helper used earlier.

Below the ToolStrip, there is a TabControl with two pages. The first contains a TreeView that lists all the tables, views, and Stored Procedures found in the database defined by the current connection string. Users may preview the data by double-clicking the tree nodes or by selecting a node and clicking the Preview button.

The second tab page contains a TextBox that contains the SQL statement generated by the QueryDesignerDialog. This TextBox is read/write, so users can cut, paste, or edit the SQL statement manually if they choose to do so.

Limitations

The main limitation in this initial version is the fact that it can generate new SQL statements, but it cannot edit existing ones. To overcome this limitation, the next version will need a SQL parser that will take an existing SQL string apart and generate the corresponding QueryField objects. This may be easy to do in some cases, but SQL is a rich and flexible language, so the task is not trivial and that is why it is not included here.

Another limitation is the fact that the whole implementation relies on OLEDB connection strings. This is not a serious limitation since OLEDB is a flexible data source, supporting SQL Server, Oracle, ODBC, Access (Jet), and many others. However, native implementations may be more efficient than the corresponding OLEDB version, and the SQL may require syntax adjustments. I have not looked into this very much at all, so if you have feedback in this area, I am very interested.

Finally, although the UI was loosely based on traditional tools like SQL Server Management Studio and Access, it deviates from that in the way tables and views are presented to the users. Personally, I like the approach used here, using a simple TreeView that is complete and easy to navigate, and configured by expanding and collapsing nodes with the mouse or keyboard. But I am sure many people will prefer the more traditional approach showing a pane with tables represented by floating lists and lines showing the connections between the tables. I am interested in your feedback in this area as well.

Conclusion

Thanks for your interest. I hope you enjoy the QueryDesignerDialog class, and would love to get your feedback.

About the Author

Bernardo Castilho


Member

Occupation: Other
Company: ComponentOne
Location: United States United States
 

Pictures Products

Newsletter

Newsletter with the latest content and changes to your site simply aware










Advertise

poll

IR-WIN site to see how
 

Calendar

 
Wednesday
2010
Sep
8
 

latest news IT

Satellite, overcoming gravity to ascend hoisted on the sky

confidence-building and satellite, driving engine for the development of other advanced regards is considered to be on the other shows and scientific management can be up in the countries of this technology.

 

According to IRNA, Iranian success researchers hope the satellite with the satellite 2 ambassador last year in the first practical step in its native space technology is considered to be able to name of Iran in the few member countries registered world space club.
Also this year with the unveiling of the national satellite television station, national Mesbah 2 satellite and satellite promise of Science and Industry and also the engine satellite Simurgh that day 14 February with the national day was done space technology, ground for presence of Iran in the arena space has been provided.
Satellite rise can be three years to remain in space, 100 kilograms and height in orbit 500 miles from the ground. The Satellite "Simurgh" You can also shipments weighing 100 kilograms in height 500 km from the earth.
according to experts, for Satellite is necessary many sciences and arts beside each other to such a project to be enforced.
***A satellite how to throw the circuit.
To put to a satellite in orbit of the earth, the force is needed for a lot. This force, ماهواره‌بر (carrying missiles) production. Satellite to be in orbit in high altitude more than 200 miles from the earth's surface above the speed of 29000 kilometers per hour.
Satellite ‌بر‌ها missiles to form a stage, with chemical burning fuel. . .
Read more...
Copyright © 2010 سیستم عامل جدید ایرانیان v2.88. All Rights Reserved.
ChakadCo! CopyRight & PowerBy GNU/GPL License.