8 Replies - 1431 Views - Last Post: 14 May 2012 - 06:35 PM Rate Topic: -----

#1 Iamateur  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 62
  • Joined: 20-April 12

Is it possible to show only particular records in gridview with req.

Posted 13 May 2012 - 08:15 AM

There are 2 textboxs to accept from date and to date.

I will be comparing the fromdate value and todate with the table column.

If the record matches then only that row will get display in the datagridview.
Is This A Good Question/Topic? 0
  • +

Replies To: Is it possible to show only particular records in gridview with req.

#2 Nerfpl  Icon User is offline

  • D.I.C Head

Reputation: 43
  • View blog
  • Posts: 165
  • Joined: 15-January 12

Re: Is it possible to show only particular records in gridview with req.

Posted 13 May 2012 - 08:22 AM

Parse your textbox to DateTime and compare 2 DataTime objects.
Was This Post Helpful? 0
  • +
  • -

#3 Iamateur  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 62
  • Joined: 20-April 12

Re: Is it possible to show only particular records in gridview with req.

Posted 13 May 2012 - 08:34 AM

View PostNerfpl, on 13 May 2012 - 08:22 AM, said:

Parse your textbox to DateTime and compare 2 DataTime objects.


Can you please elaborate?
I tried to do in this way.
con.Open()
        cmd = New SqlCommand("SELECT COUNT(*) FROM IssueMBA WHERE ida=textbox1.text,rda=textbox2.text", con)
        dr = cmd.ExecuteReader()
        If Not dr.Read() Then
            MsgBox("Invalid details")
        ElseIf 

After **ElseIf** I am not able to write exact code.
I want to show those particular rows in the gridview and that code should be shown in else part.

View PostNerfpl, on 13 May 2012 - 08:22 AM, said:

Parse your textbox to DateTime and compare 2 DataTime objects.


Did you mean in this way?
frmDate = Date.Parse(TextBox1.Text)
        toDate = Date.Parse(TextBox2.Text)
        call1(frmDate, toDate)


But then how to show it in datagridview?
I want to show that particular row.

This post has been edited by Atli: 14 May 2012 - 06:31 PM
Reason for edit:: Added [code] tags.

Was This Post Helpful? 0
  • +
  • -

#4 Iamateur  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 62
  • Joined: 20-April 12

Re: Is it possible to show only particular records in gridview with req.

Posted 13 May 2012 - 11:10 PM

2 textboxes to accept fromdate and todate and check with the database column of ida,rda and if matches then display only that row.
I tried it in the below way but not able to do.
con.Open()
        i = DataGridView1.CurrentCell.RowIndex
        cmd = New SqlCommand("SELECT COUNT(*) FROM IssueMBA WHERE ida='" + TextBox1.Text + "'and  rda='" + TextBox2.Text + "'", con)
        dr = cmd.ExecuteReader()
        If Not dr.Read() Then
            MsgBox("Invalid details")
        ElseIf ((dr(3).ToString() = TextBox1.Text) And (dr(4).ToString() = TextBox2.Text)) Then
            DataGridView1.Rows(i).Cells(0).Value.ToString()
            DataGridView1.Rows(i).Cells(1).Value.ToString()
            DataGridView1.Rows(i).Cells(2).Value.ToString()
            DataGridView1.Rows(i).Cells(3).Value.ToString()
            DataGridView1.Rows(i).Cells(4).Value.ToString()
        End If




        con.Close()

This post has been edited by Atli: 14 May 2012 - 06:31 PM
Reason for edit:: Added [code] tags.

Was This Post Helpful? 0
  • +
  • -

#5 polens  Icon User is offline

  • D.I.C Head

Reputation: 13
  • View blog
  • Posts: 155
  • Joined: 09-November 09

Re: Is it possible to show only particular records in gridview with req.

Posted 14 May 2012 - 12:14 AM

query should have BETWEEN CLAUSE or use Greater or Less than symbols to get the data . .
Was This Post Helpful? 0
  • +
  • -

#6 Iamateur  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 62
  • Joined: 20-April 12

Re: Is it possible to show only particular records in gridview with req.

Posted 14 May 2012 - 12:25 AM

View Postpolens, on 14 May 2012 - 12:14 AM, said:

query should have BETWEEN CLAUSE or use Greater or Less than symbols to get the data . .


Ok as per your reply I did like this:
ElseIf ((dr(0).ToString() >= TextBox1.Text) And (dr(0).ToString() <= TextBox2.Text)) Then
            DataGridView1.Rows(i).Cells(0).Value.ToString()
            DataGridView1.Rows(i).Cells(1).Value.ToString()
            DataGridView1.Rows(i).Cells(2).Value.ToString()
            DataGridView1.Rows(i).Cells(3).Value.ToString()
            DataGridView1.Rows(i).Cells(4).Value.ToString()


But still its not working dear.

This post has been edited by Atli: 14 May 2012 - 06:31 PM
Reason for edit:: Added [code] tags.

Was This Post Helpful? 0
  • +
  • -

#7 polens  Icon User is offline

  • D.I.C Head

Reputation: 13
  • View blog
  • Posts: 155
  • Joined: 09-November 09

Re: Is it possible to show only particular records in gridview with req.

Posted 14 May 2012 - 12:52 AM

your doing it wrong..
con.Open()
i = DataGridView1.CurrentCell.RowIndex
cmd = New SqlCommand([color="#FF0000"]"SELECT COUNT(*) FROM IssueMBA WHERE ida='" + TextBox1.Text + "'and rda='" + TextBox2.Text + "'"[/color], con)
dr = cmd.ExecuteReader()


query should be

Quote

SELECT COUNT(*) FROM TABLE WHERE DATE BETWEEN date1 AND date2

i think your table fields is not normalized

you said FROMDATE AND TODATE you only need 1 date in the table for that type of query

This post has been edited by polens: 14 May 2012 - 12:58 AM

Was This Post Helpful? 0
  • +
  • -

#8 CharlieMay  Icon User is offline

  • This space intentionally left blank
  • member icon

Reputation: 1606
  • View blog
  • Posts: 5,163
  • Joined: 25-September 09

Re: Is it possible to show only particular records in gridview with req.

Posted 14 May 2012 - 02:37 PM

You realize that Count is going to return a number right?
Was This Post Helpful? 0
  • +
  • -

#9 Atli  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 3730
  • View blog
  • Posts: 6,017
  • Joined: 08-June 10

Re: Is it possible to show only particular records in gridview with req.

Posted 14 May 2012 - 06:35 PM

** Threads merged **

Iamateur, do not double post your questions! And please remember to use [code] tags when posting code.

:code:
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1