0
Answer

Datagrid populated through textbox date range?

Ask a question
Sean

Sean

14y
3.2k
1

I have a datagrid that I want to be populated by two text boxes based on the dates in the textboxes. At this point i cant get my sql string to read the text boxes and fill the datagrid. I can't get this to work, can someone please help, thanks in advance!!
 
Here's my connection to the database.
Sub Page_Load(sender as Object, e as EventArgs)
   'BindData()
 
  End Sub
  'Sub BindData()
  Public Sub Submit_Click(ByVal sender As Object, ByVal e As System.EventArgs)
    '1. Create a connection
 Dim strTxt as String
 Dim conn as SQLconnection
 Dim da as New SQLdataAdapter
 Dim ds as New DataSet()
 Dim cmd as SQLcommand
 Dim newListItem1 as new ListItem()
 Dim submit AS button
 Dim beginDate As date
 Dim endDate As Date
 'Dim txtBeginDate As textbox
 'Dim txtEndDate As textbox
 txtBeginDate.text = beginDate
 txtEndDate.text = endDate
    conn = New SQLconnection("server=xxxxx; database=xxxxx; uid=xxxxx; pwd=xxxxx")
strTxt = "SELECT ID, MRN, Name, CheckInDate, Dept, Prov, DX1, DX1Desc, CPT1, CPT1Desc FROM OPPE_Clinic WHERE CheckInDate >= '"& beginDate & "' and CheckInDate <= '" & endDate & "' "
 
cmd = New SQLcommand(strTxt, conn)
    '2. Create the command object, passing in the SQL string
    Dim myCommand as New SqlCommand(strTxt, conn)
 Dim myAdapter as New SqlDataAdapter(myCommand)
 
 'Dim ds as New DataSet()
 myAdapter.Fill(ds)
    'Set the datagrid's datasource to the datareader and databind
    conn.Open()
    PPROClinic.DataSource = ds
    PPROClinic.DataBind() 
 One.text = FormatDateTime(beginDate,2)
 CheckInDate = Two.text
  End Sub
</script>
Below is my datagrid and text boxes.
<html>
<head>
<title>Chief's Corner - PPRO</title>
<meta http-equiv="Content-Type" content="text/html;">
</head>
<body style="margin:0">
<FORM METHOD=POST ACTION="" runat=server>
<table border=0 bgcolor="#F9F9F2" height=455 width=800>
<tr>
    <td colspan=15 heigth=10 class="content">Begin Date:&nbsp;<asp:textbox ID="txtBeginDate" NAME="txtBeginDate" runat="server" class="content" />&nbsp;&nbsp;End Date:&nbsp;<asp:textbox id="txtEndDate" NAME="txtEndDate" runat="server" class="content" />&nbsp;&nbsp;<asp:Button id="submit" runat="server" Text="Submit" OnClick="Submit_Click"></asp:Button></td>
  </tr>
  <tr>
    <td>
  Date 1: <asp:Label id="One" runat=server /><br>
  Date 2: <asp:Label id="Two" runat=server />
 </td>
  </tr>
  <tr>
    <td><asp:datagrid id="PPROClinic" runat="server" class="content" />
   <columns>
 <asp:BoundColumn datafield="ID" headertext="ID" ItemStyle-Width="5%" />
 <asp:BoundColumn datafield="MRN" headertext="MRN" ItemStyle-Width="5%" />
 <asp:BoundColumn datafield="Name" headertext="Name" />
 <asp:BoundColumn datafield="CheckInDate" DataFormatString="{0:d}" headertext="Check In Date" ItemStyle-Width="10%" />
 <asp:BoundColumn datafield="Dept" headertext="Dept" ItemStyle-Width="8%" />
 <asp:BoundColumn datafield="Prov" headertext="Provider" ItemStyle-Width="18%" />
 <asp:BoundColumn datafield="DX1" headertext="DX1" />
 <asp:BoundColumn datafield="Dx1Desc" headertext="Dx1Desc" ItemStyle-Width="15%" />
 <asp:BoundColumn datafield="CPT1" headertext="CPT1" />
 <asp:BoundColumn datafield="CPT1Desc" headertext="CPT1Desc" ItemStyle-Width="12%" />
 </columns>
 </asp:DataGrid>
 </td>
  </tr>
</table>
</FORM>