Using parameterized queries to retrieve the matching table rows by clicking radio buttons and displaying them in a DataGridView Control










0














I am creating a program that uses a table of karate members from a database that allows the user to select a date from a DateTimePicker control. The program displays the first name, last name, phone #'s and dates joined of all members who joined before the selected date. I need to use a a parameterized query to retrieve the matching table rows and display them in a DataGridView Control. After that, I need add radio button that allows the user to choose before this date or on or after this date.



So far, I created the DateTimePicker control from Dates_Joined in the members data set and included the data grid view. I then added two radio buttons from the Dates_Joined in the members data set, and tried creating a query for each. It is not working properly for getting the filtered rows after specifying the date from the picker and then clicking on either the before or on or after this date radio button.



Public Class Form1
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
'TODO: This line of code loads data into the 'KarateDataSet.Members' table. You can move, or remove it, as needed.
Me.MembersTableAdapter.Fill(Me.KarateDataSet.Members)

End Sub

Private Sub BeforeToolStripButton_Click(sender As Object, e As EventArgs) Handles BeforeToolStripButton.Click
Try
Me.MembersTableAdapter.Before(Me.KarateDataSet.Members, New System.Nullable(Of Date)(CType(Date_JoinedToolStripTextBox.Text, Date)))
Catch ex As System.Exception
System.Windows.Forms.MessageBox.Show(ex.Message)
End Try

End Sub

Private Sub FillByToolStripButton_Click(sender As Object, e As EventArgs) Handles FillByToolStripButton.Click
Try
Me.MembersTableAdapter.FillBy(Me.KarateDataSet.Members, New System.Nullable(Of Date)(CType(Date_JoinedToolStripTextBox1.Text, Date)))
Catch ex As System.Exception
System.Windows.Forms.MessageBox.Show(ex.Message)
End Try

End Sub
End Class









share|improve this question























  • Firstly, you should not have a method named FillBy. The idea is that you specify the filter(s) in the method name. You want to be able to query in three different ways so you should add three queries to your table adapter. They each filter by Dates_Joined but each in a different way, i.e. Dates_Joined < ?, Dates_Joined = ? and Dates_Joined > ?. The methods should be named FillByBeforeDatesJoined, FillByOnDatesJoined and FillByAfterDatesJoined or the like. You then call whichever method is appropriate at the time.
    – jmcilhinney
    Nov 12 '18 at 21:37










  • That said, it appears that you're actually calling Fill when the form loads and thus getting all the data upfront. If that's the case then there's no point querying again to get data you already have. You should just filter the data you have by setting the Filter property of the BindingSource bound to the grid.
    – jmcilhinney
    Nov 12 '18 at 21:38










  • Also, you say that you are using a DateTimePicker and yet your code is actually using a ToolStringTextBox. What's up with that?
    – jmcilhinney
    Nov 12 '18 at 21:39















0














I am creating a program that uses a table of karate members from a database that allows the user to select a date from a DateTimePicker control. The program displays the first name, last name, phone #'s and dates joined of all members who joined before the selected date. I need to use a a parameterized query to retrieve the matching table rows and display them in a DataGridView Control. After that, I need add radio button that allows the user to choose before this date or on or after this date.



So far, I created the DateTimePicker control from Dates_Joined in the members data set and included the data grid view. I then added two radio buttons from the Dates_Joined in the members data set, and tried creating a query for each. It is not working properly for getting the filtered rows after specifying the date from the picker and then clicking on either the before or on or after this date radio button.



Public Class Form1
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
'TODO: This line of code loads data into the 'KarateDataSet.Members' table. You can move, or remove it, as needed.
Me.MembersTableAdapter.Fill(Me.KarateDataSet.Members)

End Sub

Private Sub BeforeToolStripButton_Click(sender As Object, e As EventArgs) Handles BeforeToolStripButton.Click
Try
Me.MembersTableAdapter.Before(Me.KarateDataSet.Members, New System.Nullable(Of Date)(CType(Date_JoinedToolStripTextBox.Text, Date)))
Catch ex As System.Exception
System.Windows.Forms.MessageBox.Show(ex.Message)
End Try

End Sub

Private Sub FillByToolStripButton_Click(sender As Object, e As EventArgs) Handles FillByToolStripButton.Click
Try
Me.MembersTableAdapter.FillBy(Me.KarateDataSet.Members, New System.Nullable(Of Date)(CType(Date_JoinedToolStripTextBox1.Text, Date)))
Catch ex As System.Exception
System.Windows.Forms.MessageBox.Show(ex.Message)
End Try

End Sub
End Class









share|improve this question























  • Firstly, you should not have a method named FillBy. The idea is that you specify the filter(s) in the method name. You want to be able to query in three different ways so you should add three queries to your table adapter. They each filter by Dates_Joined but each in a different way, i.e. Dates_Joined < ?, Dates_Joined = ? and Dates_Joined > ?. The methods should be named FillByBeforeDatesJoined, FillByOnDatesJoined and FillByAfterDatesJoined or the like. You then call whichever method is appropriate at the time.
    – jmcilhinney
    Nov 12 '18 at 21:37










  • That said, it appears that you're actually calling Fill when the form loads and thus getting all the data upfront. If that's the case then there's no point querying again to get data you already have. You should just filter the data you have by setting the Filter property of the BindingSource bound to the grid.
    – jmcilhinney
    Nov 12 '18 at 21:38










  • Also, you say that you are using a DateTimePicker and yet your code is actually using a ToolStringTextBox. What's up with that?
    – jmcilhinney
    Nov 12 '18 at 21:39













0












0








0







I am creating a program that uses a table of karate members from a database that allows the user to select a date from a DateTimePicker control. The program displays the first name, last name, phone #'s and dates joined of all members who joined before the selected date. I need to use a a parameterized query to retrieve the matching table rows and display them in a DataGridView Control. After that, I need add radio button that allows the user to choose before this date or on or after this date.



So far, I created the DateTimePicker control from Dates_Joined in the members data set and included the data grid view. I then added two radio buttons from the Dates_Joined in the members data set, and tried creating a query for each. It is not working properly for getting the filtered rows after specifying the date from the picker and then clicking on either the before or on or after this date radio button.



Public Class Form1
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
'TODO: This line of code loads data into the 'KarateDataSet.Members' table. You can move, or remove it, as needed.
Me.MembersTableAdapter.Fill(Me.KarateDataSet.Members)

End Sub

Private Sub BeforeToolStripButton_Click(sender As Object, e As EventArgs) Handles BeforeToolStripButton.Click
Try
Me.MembersTableAdapter.Before(Me.KarateDataSet.Members, New System.Nullable(Of Date)(CType(Date_JoinedToolStripTextBox.Text, Date)))
Catch ex As System.Exception
System.Windows.Forms.MessageBox.Show(ex.Message)
End Try

End Sub

Private Sub FillByToolStripButton_Click(sender As Object, e As EventArgs) Handles FillByToolStripButton.Click
Try
Me.MembersTableAdapter.FillBy(Me.KarateDataSet.Members, New System.Nullable(Of Date)(CType(Date_JoinedToolStripTextBox1.Text, Date)))
Catch ex As System.Exception
System.Windows.Forms.MessageBox.Show(ex.Message)
End Try

End Sub
End Class









share|improve this question















I am creating a program that uses a table of karate members from a database that allows the user to select a date from a DateTimePicker control. The program displays the first name, last name, phone #'s and dates joined of all members who joined before the selected date. I need to use a a parameterized query to retrieve the matching table rows and display them in a DataGridView Control. After that, I need add radio button that allows the user to choose before this date or on or after this date.



So far, I created the DateTimePicker control from Dates_Joined in the members data set and included the data grid view. I then added two radio buttons from the Dates_Joined in the members data set, and tried creating a query for each. It is not working properly for getting the filtered rows after specifying the date from the picker and then clicking on either the before or on or after this date radio button.



Public Class Form1
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
'TODO: This line of code loads data into the 'KarateDataSet.Members' table. You can move, or remove it, as needed.
Me.MembersTableAdapter.Fill(Me.KarateDataSet.Members)

End Sub

Private Sub BeforeToolStripButton_Click(sender As Object, e As EventArgs) Handles BeforeToolStripButton.Click
Try
Me.MembersTableAdapter.Before(Me.KarateDataSet.Members, New System.Nullable(Of Date)(CType(Date_JoinedToolStripTextBox.Text, Date)))
Catch ex As System.Exception
System.Windows.Forms.MessageBox.Show(ex.Message)
End Try

End Sub

Private Sub FillByToolStripButton_Click(sender As Object, e As EventArgs) Handles FillByToolStripButton.Click
Try
Me.MembersTableAdapter.FillBy(Me.KarateDataSet.Members, New System.Nullable(Of Date)(CType(Date_JoinedToolStripTextBox1.Text, Date)))
Catch ex As System.Exception
System.Windows.Forms.MessageBox.Show(ex.Message)
End Try

End Sub
End Class






sql vb.net






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 12 '18 at 21:31









jmcilhinney

25.4k21932




25.4k21932










asked Nov 12 '18 at 20:56









Rick

53




53











  • Firstly, you should not have a method named FillBy. The idea is that you specify the filter(s) in the method name. You want to be able to query in three different ways so you should add three queries to your table adapter. They each filter by Dates_Joined but each in a different way, i.e. Dates_Joined < ?, Dates_Joined = ? and Dates_Joined > ?. The methods should be named FillByBeforeDatesJoined, FillByOnDatesJoined and FillByAfterDatesJoined or the like. You then call whichever method is appropriate at the time.
    – jmcilhinney
    Nov 12 '18 at 21:37










  • That said, it appears that you're actually calling Fill when the form loads and thus getting all the data upfront. If that's the case then there's no point querying again to get data you already have. You should just filter the data you have by setting the Filter property of the BindingSource bound to the grid.
    – jmcilhinney
    Nov 12 '18 at 21:38










  • Also, you say that you are using a DateTimePicker and yet your code is actually using a ToolStringTextBox. What's up with that?
    – jmcilhinney
    Nov 12 '18 at 21:39
















  • Firstly, you should not have a method named FillBy. The idea is that you specify the filter(s) in the method name. You want to be able to query in three different ways so you should add three queries to your table adapter. They each filter by Dates_Joined but each in a different way, i.e. Dates_Joined < ?, Dates_Joined = ? and Dates_Joined > ?. The methods should be named FillByBeforeDatesJoined, FillByOnDatesJoined and FillByAfterDatesJoined or the like. You then call whichever method is appropriate at the time.
    – jmcilhinney
    Nov 12 '18 at 21:37










  • That said, it appears that you're actually calling Fill when the form loads and thus getting all the data upfront. If that's the case then there's no point querying again to get data you already have. You should just filter the data you have by setting the Filter property of the BindingSource bound to the grid.
    – jmcilhinney
    Nov 12 '18 at 21:38










  • Also, you say that you are using a DateTimePicker and yet your code is actually using a ToolStringTextBox. What's up with that?
    – jmcilhinney
    Nov 12 '18 at 21:39















Firstly, you should not have a method named FillBy. The idea is that you specify the filter(s) in the method name. You want to be able to query in three different ways so you should add three queries to your table adapter. They each filter by Dates_Joined but each in a different way, i.e. Dates_Joined < ?, Dates_Joined = ? and Dates_Joined > ?. The methods should be named FillByBeforeDatesJoined, FillByOnDatesJoined and FillByAfterDatesJoined or the like. You then call whichever method is appropriate at the time.
– jmcilhinney
Nov 12 '18 at 21:37




Firstly, you should not have a method named FillBy. The idea is that you specify the filter(s) in the method name. You want to be able to query in three different ways so you should add three queries to your table adapter. They each filter by Dates_Joined but each in a different way, i.e. Dates_Joined < ?, Dates_Joined = ? and Dates_Joined > ?. The methods should be named FillByBeforeDatesJoined, FillByOnDatesJoined and FillByAfterDatesJoined or the like. You then call whichever method is appropriate at the time.
– jmcilhinney
Nov 12 '18 at 21:37












That said, it appears that you're actually calling Fill when the form loads and thus getting all the data upfront. If that's the case then there's no point querying again to get data you already have. You should just filter the data you have by setting the Filter property of the BindingSource bound to the grid.
– jmcilhinney
Nov 12 '18 at 21:38




That said, it appears that you're actually calling Fill when the form loads and thus getting all the data upfront. If that's the case then there's no point querying again to get data you already have. You should just filter the data you have by setting the Filter property of the BindingSource bound to the grid.
– jmcilhinney
Nov 12 '18 at 21:38












Also, you say that you are using a DateTimePicker and yet your code is actually using a ToolStringTextBox. What's up with that?
– jmcilhinney
Nov 12 '18 at 21:39




Also, you say that you are using a DateTimePicker and yet your code is actually using a ToolStringTextBox. What's up with that?
– jmcilhinney
Nov 12 '18 at 21:39












0






active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53269970%2fusing-parameterized-queries-to-retrieve-the-matching-table-rows-by-clicking-radi%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53269970%2fusing-parameterized-queries-to-retrieve-the-matching-table-rows-by-clicking-radi%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







這個網誌中的熱門文章

How to read a connectionString WITH PROVIDER in .NET Core?

In R, how to develop a multiplot heatmap.2 figure showing key labels successfully

Museum of Modern and Contemporary Art of Trento and Rovereto