1 Attachment(s)
Display query result in data grid view
Hello all , I am very new to visual studio and i am very interested in learning vb.net language even though i don't have much of programming experience.
I am creating a winform app for data entry connected to a access-db as source.
I have a data grid box in form2(name:reminder) which will pop up when clicked on a button in form1(name:MSdies).
In this form2 data-grid box i just want view the query results i have created as below SQL :
Code:
SELECT ID, [Size in mg], [Die head number], [Inspection Date], [Next Calibration Date], [Die size in microns]
FROM MSdies
WHERE ([Next Calibration Date] < NOW())
originally the table contains these details
Code:
SELECT ID, [Size in mg], [Die head number], [Inspection Date], [Next Calibration Date], [Die size in microns], [Condition of DIE-1], [Condition of DIE-2], [Condition of DIE-3], [Condition of DIE-4], [Condition of DIE-5], [Condition of DIE-6],[Condition of DIE-7], Observations, Inspector
FROM MSdies
Can anyone help me with this how can i achieve the same by step wise explanation.
for database name & details
Code:
Private Sub Reminder_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Me.MSdiesTableAdapter.Fill(Me.TrialdatabaseDataSet.MSdies)
End Sub
I have attached images too for your reference.Attachment 177998
Re: Display query result in data grid view
First things first, when you add a query to your table adapter you're supposed to name the generated method(s) sensibly. FillBy and FillBy1 are hardly sensible names. If all you're doing is adding a filter then you're supposed to add the filter to the name, e.g. if you have a WHERE clause that filters by ParentId then the method should be named FillByParentId. If the query is more complex then you may need a more complex name but that's fine. Despite what some people seem to think, long method names are fine in these days of Intellisense.
As for the question, you have two options. The new query doesn't generate the same schema as the existing query so you cannot add that query to the same table adapter. You could use a query with all the columns, so that the schemas match, and just ignore the columns you don't need. You'd then add a FillByNextCalibrationDate method to the table adapter and use that the same as you would the Fill method. The second option is to create a new table adapter and DataTable pair that have the schema you want. There's no issue having multiple DataTables and table adapters for the same source table if you want multiple result schemas.
By the way, it really is a bad idea to include spaces in database column names. You're just going to make things harder for yourself. You should name columns the same way you would a property in VB. You should think of tables and properties as being the database equivalent of classes and properties. Each row is like an instance of the class with the properties set to specific values.
Re: Display query result in data grid view
Quote:
The second option is to create a new table adapter and DataTable pair that have the schema you want. There's no issue having multiple DataTables and table adapters for the same source table if you want multiple result schemas.
Thank you so much for your reply ...sorry about the column names and i will implement the same .
Regarding creating new table adapter with filtered data ..could you please teach me further step wise taking the above sample as example ?
The theory you explained is understandable but until i practically see through with example ..i can't learn or follow along.sorry for the inconvenience & i am sure i will learn this vb.net & visual studio very fast.
Re: Display query result in data grid view
Quote:
Originally Posted by
Ravikumar12233
until i practically see through with example ..i can't learn or follow along.
I disagree. You can try for yourself and see what happens. The problem is often that people don't know how to do things because they don't look to see what's available to them. Have you explored the DataSet designer to see what it can do? I'd wager not. It's not going to read your mind and jump out at you with the information you need. You have to go looking for it. That is exactly how I learned so much of what I know and it also has the advantage of exposing you to things that you may not need right now but will come in handy later. If you'd explored the DataSet designer when you first started using it then you wouldn;t be asking this question now because you'd already have found that information. You don't have to sit and wait for information to come to you. You can go and look for it. You can do that with a test project first, to get a handle on the principles before applying them to your working project, or you can take a backup of your working project and then experiment on it directly, knowing you can fall back to a working copy if you break it.