datagrid
Hi, I am trying to bind my recordset to a datagrid but it doesn't work. I did response.write to see if it in fact receives the correct records and it does. The only problem is with the databinding. Can someone please help me? Thanks aspx.vb Private oConn As New SqlConnection(Constants.SQLProviderConnectionString) Private cmd As SqlCommand Private AD_ApprovedState Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load 'Put user code to initialize the page here fillTable() End Sub Public Sub fillTable() AD_ApprovedState = "1" If AD_ApprovedState = "" Then AD_ApprovedState = "0" End If cmd = oConn.CreateCommand cmd.CommandText = "select * from ads where ad_approved=@AD_ApprovedState" cmd.Parameters.Add("@AD_ApprovedState", AD_ApprovedState) oConn.Open() Dim DR As SqlDataReader DR = cmd.ExecuteReader Do While DR.Read = True ad_title = CStr(DR("ad_title")) ad_poster = CType(DR("ad_poster"), String) ad_man = CType(DR("ad_man"), String) date_expired = CType(DR("ad_expired"), String) date_start = CType(DR("ad_dated"), String) ad_id = CType(DR("ad_id"), Int32) Loop DataGrid1.DataSource = DR DataGrid1.DataBind() DR.Close() oConn.Close() ASPX: <asp:datagrid id="DataGrid1" runat="server"> <Columns> <asp:BoundColumn HeaderText="Title" DataField="ad_title" /> <asp:BoundColumn HeaderText="Owner" DataField="ad_poster" /> <asp:BoundColumn HeaderText="Date Expired" DataField="ad_expired" /> <asp:BoundColumn HeaderText="Date" DataField="ad_dated" /> <asp:BoundColumn HeaderText="Manager" DataField="ad_man" /> <asp:BoundColumn HeaderText="Quantity" DataField="ad_quantity" /> <asp:BoundColumn HeaderText="AD_ID" DataField="ad_id" /> </Columns> </asp:datagrid>