Limit tables shown in DevExpress Dashboard - Query Builder - devexpress

Im trying to limit the tables shown in the DevExpress Dashboard Query Builder.
I tried adding Queries like below but the Query Builder still show all tables in the database.
Is there a way to limit the tables shown in the Query Builder?
DataSourceInMemoryStorage dataSourceStorage = new DataSourceInMemoryStorage();
DashboardSqlDataSource sqlDataSource = new DashboardSqlDataSource("MyApp", customstringParams);
SelectQuery selectQuery = SelectQueryFluentBuilder
.AddTable("EMPLOYEE_DETAIL", "Employee Master")
.SelectAllColumns()
.Build("Employee Information");
sqlDataSource.Queries.Add(selectQuery);
SelectQuery selectQuery2 = SelectQueryFluentBuilder
.AddTable("EMPLOYEE_ATTENDANCE", "Shift Distribution")
.SelectAllColumns()
.Build("Shift Distribution");
sqlDataSource.Queries.Add(selectQuery2);
sqlDataSource.Fill();
dataSourceStorage.RegisterDataSource("sqlDataSource", sqlDataSource.SaveToXml());
DashboardConfigurator.Default.SetDataSourceStorage(dataSourceStorage);

To accomplish this task, use the approach described in Query Builder - Limit the list of available Stored Procedures, Tables, or Views.

Related

Xamarin SQLite Query

I try to create a query in the shard project in xamarin.
I can successfully create a connection to my local DB with dependecy services. But I'm not able to create a query.
Here is my code:
Connection to DB(successfully)
SQLite.SQLiteConnection DBConnection = DependencyService.Get<IDBHelper>().DbConnection(DBPath);
Get table Info (successfully)
var TableInfo = DBConnection.GetTableInfo("SomeTableName");
Query (failed)
var ReturnValue = DBConnection.Query<string>("Select * from SomeTable Where SomeColumn Like 'Value'");
Viusal Studio shows me the problem, its the <string> part. But I have no idea what I have to change.
How can I create a simple select query?
You are probably using the SQLite-Net package. This works like an ORM over SQLite database.
The generic part (where you did put <string>) is the type of object that the query must expect when getting results.
It will automatically turn the resultset into a list of your queried type.
As you are querying all data from the SomeTable table each row will represent a SomeTable object (I guess you have created such class).
Just change this line to:
var ReturnValue = DBConnection.Query<SomeTable>("Select * from SomeTable Where SomeColumn Like 'Value'");
or
var ReturnValue = DBConnection.Query<object>("Select * from SomeTable Where SomeColumn Like 'Value'");
You can get a step by step using SQLite at the official sqlite-net documentation.
I hope it helps.

What do I need to learn for accessing data from mssql database?

I am learning asp.net core mvc and API. I can simply work on it for CRUD operation. But, I get confused for accessing data from multiple tables like listing all categories with showing number of items each categories contains. What I need to learn for example Lina, entity framework code first, ado.net? I am currently using entity framework code first.
Thanks
Learn Dapper a simple object mapper for .NET.
What I Understood from your problem is that you have multiple tables and you want to query them and map the query result in your c# or vb code.Here I will show simple mapping of query result to c# objects.
Suppose you have three tables category_1,category_2 and category_3.
Lets say each table have two columns named itemName and ItemValue.
Lets create c# class corresponding to each table.
class category_1{
string ItemName {get;set};
int ItemValue {get;set;};
}
class category_2{
string ItemName {get;set};
int ItemValue {get;set;};
}
class category_3{
string ItemName {get;set};
int ItemValue {get;set;};
}
Suppose your querying three tables and map the result of query to respective object in c#.
let our sql query be as follows:
string sql = #"select * from category_1;select * from category_2;select * from category_3;"
Here we have three select statements and each select statement will give you result of respective table.Lets query the above sql to database using dapper and map them to c# object as follows.
List<category_1> lstCotegory1 = new List<category_1>();
List<category_2> lstCotegory2 = new List<category_2>();
List<category_3> lstCotegory3 = new List<category_3>();
using (var multi = connection.QueryMultiple(sql))
{
lstCotegory1 = multi.Read<category_1>().ToList(); // map first select statement
lstCotegory2 = multi.Read<category_2>().ToList(); // map second select statement
lstCotegory3 = multi.Read<category_3>().ToList(); // map third select statement.
}
This is how you can return results of multiple queries and map them to appropriate object. I know you can do better than this but to understand we have to go with simple example.Hope this will help.

Entity Framework Update Time & Date Column with Parameterized

I have changed all my code from the raw ADO.NET SQLCommand to Entity Framework in order to have easier accessibility of changing my code in the future. However, I have realized there are many drawbacks in Entity Framework it is not as simple as injecting raw SQL commands into the database. Moreover, I have used Reverse Engineering to generate the Models & Mapping for MS Sql Server.
Currently, I am trying to do the following but none of the columns are getting updated.
string sql = #"UPDATE [ProductDB] SET CreatedProduct_Time=getdate(), CreatedProduct_Date=getdate()" + " WHERE [Material_No] = #Material_No";
db.Database.ExecuteSqlCommand(sql, new SqlParameter("#Material_No", materialnotxt));
The columns are not getting updated.
I am having a doubt whether Entity Framework will help me maintain my code for future use and is it worth the headache using it instead of the old raw SQL code? So far there are many constraints and it requires a higher learning curve.
Some confusing parts I have find online what is the difference between the context.Database.ExecuteSqlCommand and this MSDN http://msdn.microsoft.com/en-us/library/bb738684.aspx the code looks entirely different then my approach.
EDIT
I have used a different approach to insert the Date and Time while inserting all the info from the textbox.
using (var db = new ROGContext())
{
ProductDB product = new ProductDB
{
Material_No = long.Parse(MaterialNo_txtbox.Text),
Product_Line = ProductLineDropDownList1.SelectedItem.Text,
Product_Description = Description_txtbox.Text,
Size = Size_txtbox.Text,
UOM = UOM_txtbox.Text,
SupplierID = long.Parse(SupplierCountryListBox.SelectedItem.Value),
CreatedProduct_Date = DateTime.Parse(System.DateTime.Now.ToShortDateString()), //in the SQL database I have set the datatype as date to get yyyy/mm/dd
CreatedProduct_Time = DateTime.Now.TimeOfDay //in the SQL database I have set the datatype as time(0) to get hh:mm:ss
};
long queryselect = (from materialno in db.ProductDBs
where materialno.Material_No == product.Material_No
select materialno.Material_No).SingleOrDefault();
if (queryselect != long.Parse(materialnotxt))
{
Label1.Text = "Product successfully added in database";
Label1.Visible = true;
db.ProductDBs.Add(product);
db.SaveChanges();
}
You can use Context.ExecuteStoreCommand for Insert, Update and Delete.
See in Page 64 of Entity Framework 4.0 Recipes: A Problem-Solution Approach
Answer your edited part:
ExecuteStoreQuery for Select
ExecuteStoreCommand for Insert, Update and Delete
Entity Framework v4 – Tips and Tricks

Linq to Entities Many to Many Query WPF DataGrid

I have a Many to Many relationship in SQL Server 2008:
Student table (StudentID as PK, StudentName)
Course table (CourseID as PK, CourseName)
StudentCourse (Pure Junction Table) (StudentID, CourseID both in a composite PK).
In Visual Studio 2010:
Entity model is setup properly.
I have a DataGrid bound to:
<CollectionViewSource x:Key="CourseViewSource" d:DesignSource="{d:DesignInstance my:Course, CreateList=True}" />"
This allows me to set the dataGrid columnsproperty to BOTH tables: CourseName AND to Students.StudentName.
I need to show ALL Students in ALL Courses they are in, on the same dataGrid.
My query is:
` var context = new context();
var List = from y in context.Courses
from z in y.Students
select y;
dataGrid1.ItemsSource = List;`
This query returns the first student in table Student in all courses and it gets repeated, but I can't show the other students that are taking the same courses AND other courses.
Question:
How can I change the query using linq to entities. I have tried many things for many days.
Thanks in advance.
Try Include instead, like this:
var List = (from y in context.Courses.Include("Students") select y).ToList();

how to query strongly type datatable

I have a news portal.
For this portal I have a database with a "News" table and with the following columns
(NewsID, CategoryID, NewsTitle, NewsText, DateAdded, ImagePath, TotalRead, NewsType, isActive)
I use dataset files (.xsd) and for this one, I have a query that returns the last 3 days' news into a custom class that I coded, named HHNews.
HHNews Class has a function that returns a strongly-typed datatable that includes the results of the query I mention above.
The home page has different sections for news.. these are;
- Headlines (5 items)
- Sub-headings (4 items)
- Last 5 news items for each of the news categories...( categories are like; sports, local news, economics,
For the home page, I retrieve the datatable returned from the class. Now I want to query this datatable and build the sections I mention above.. e.g.
if my datatable is called "dt", then is there a way to sql-like query this dt such as "select TOP(5) NewsID, NewsTitle, NewsText from dt where NewsType = 0" -- 0 representing the headline ?
Absolutely. You can use LINQ as Dave Cluderay mentioned. To retrieve your headlines, for example, you could run:
var myDataTable = dt.AsEnumerable();
var headlines = myDataTable.Where(t => t.NewsID == 0).Take(5);
You can use LINQ to DataSet if you're in .NET 3.5.
If you aren't in .NET 3.5, you can create a DataView based on the DataTable object and then set the RowFilter property on the DataView. For example:
DataView myDV = new DataView(dt);
myDV.RowFilter = "NewsType = 0";
You can then catch only the first 5 rows in your DataView.
You can use the default view to filter the datatable like so:
dt.DefaultView.RowFilter = "NewsType = 0";
Not sure how you would get the top 5!?
If you're not in 3.5 you could use a simple for loop to get the top 5 rows after sorting the table.
There is a Select method on the Datatable, dont think there is a way to limit the amount returned. I like the LINQ way, but just an alternative....but the limit might count this out.
dt.Select("NewsType = 0");

Resources