Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Newbie Question- Datagrid paging

Status
Not open for further replies.

amorous

Programmer
Sep 5, 2003
1,008
US
Hi Guys,

This is my first attempt to create a Datagrid paging...

I have this below code(got online-made changes using my ASP knowledge) but it is not working...

it is giving error at the connectionstring to the database...it says Keyword not supported 'Provider'--i have no clue

is there something wrong with my connection...

Code:
<%@ import Namespace="System.Data" %>
 <%@ import Namespace="System.Data.SqlClient" %>

<script runat="server" language="VB">
Sub Page_Load(sender as Object, e as EventArgs)
If Not Page.IsPostBack then
 BindData()
End If
End Sub

Sub BindData()
'1. Create a connection

[COLOR=red yellow]Const strConnString as String = "Provider=SQLOLEDB; Data Source = STJSQL\STJDB; Database=STJData;User ID=XXX;Password=XXXX"[/color] 

Dim objConn as New SqlConnection(strConnString)

 '2. Create a command object for the query

    Dim strSQL as String
   strSQL = "SELECT * FROM EMPLOYEE "
    Dim objCmd as New SqlCommand(strSQL, objConn)

    '3. Create a DataAdapter and Fill the DataSet
    Dim objDA as New SqlDataAdapter()
    objDA.SelectCommand = objCmd

    objConn.Open()

    Dim objDS as DataSet = New DataSet()
    objDA.Fill(objDS, "employees")

   objConn.Close()

   'Finally, specify the DataSource and call DataBind()
   dgEmployees.DataSource = objDS
   dgEmployees.DataBind()

    objConn.Close()  'Close the connection
  End Sub
 
 Sub dgEmployees_Paging(sender As Object, e As DataGridPageChangedEventArgs)
  dgEmployees.CurrentPageIndex = e.NewPageIndex
  BindData()
End Sub
 </script>

<form runat="server">
<asp:DataGrid runat="server" id="dgEmployees"
Font-Name="Verdana" Font-Size="9pt" CellPadding="5"
AlternatingItemStyle-BackColor="#dddddd"
AutoGenerateColumns="True"
 AllowPaging="True" PageSize="5"
 OnPageIndexChanged="dgEmployees_Paging">

 <HeaderStyle BackColor="Navy" ForeColor="White" Font-Size="13pt"
 Font-Bold="True" HorizontalAlign="Center" />

<PagerStyle BackColor="Navy" ForeColor="White" Font-Size="8pt"
 Font-Bold="True" HorizontalAlign="Right"
Mode="NumericPages" PageButtonCount="3" 
 Position="TopAndBottom" />

</asp:DataGrid>
</form>


-VJ
 
Please ignore this post...i got it working...

-VJ
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top