SqlDataSource -connection problem
while i do the web application, i tried to display those details in gridview. when i configure SqlDataSource it shows an error like object reference not set to an instance of an object. anyone can help me?
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Sunny SharmaRank #223 · 11.1K reputationPosted May 21, 2013, 10:29 PM EDT
Sandeep Singh ShekhawatRank #147 · 15.6K reputationPosted May 21, 2013, 11:23 PM EDT
SqlDataSource Design Code
<asp:SqlDataSource ID="EmployeeDataSource" runat="server"
ConnectionString="Data Source=sandeepss-PC; database=development; user=sa;password=knowdev"
SelectCommand="select Id, Name, Emp_Code,Emp_Age from EMPLOYEE">
asp:SqlDataSource>
GridView Design
DataSourceID property set by SqlDataSource ID to bind grid view.
<asp:GridView ID="gvCustomres" runat="server"
DataSourceID="EmployeeDataSource"
AutoGenerateColumns="False"
GridLines="None"
AllowPaging="true"
CssClass="mGrid"
PagerStyle-CssClass="pgr"
AlternatingRowStyle-CssClass="alt"
Width=40%>
<Columns>
<asp:TemplateField HeaderText="S.No." ItemStyle-HorizontalAlign="Center">
<ItemTemplate>
<%#Container.DataItemIndex+1%>
ItemTemplate>
asp:TemplateField>
<asp:BoundField DataField="Name" HeaderText="Employee Name" />
<asp:BoundField DataField="Emp_Code" HeaderText="Employee Code" />
<asp:BoundField DataField="Emp_Age" HeaderText="Employee Age" />
Columns>
asp:GridView>
Sunny SharmaRank #223 · 11.1K reputationPosted May 22, 2013, 12:55 AM EDT
Hope this helps!!
Ravikumar G178 reputationPosted May 28, 2013, 9:02 PM EDT