8 Replies - 566 Views - Last Post: 14 May 2012 - 06:35 PM
#1
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.
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.
Replies To: Is it possible to show only particular records in gridview with req.
#3
Re: Is it possible to show only particular records in gridview with req.
Posted 13 May 2012 - 08:34 AM
Nerfpl, 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.
Nerfpl, 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.
#4
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.
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.
#5
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 . .
#6
Re: Is it possible to show only particular records in gridview with req.
Posted 14 May 2012 - 12:25 AM
polens, 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.
#7
Re: Is it possible to show only particular records in gridview with req.
Posted 14 May 2012 - 12:52 AM
your doing it wrong..
query should be
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
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
#8
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?
Page 1 of 1
|
|

New Topic/Question
Reply



MultiQuote







|