Reputation: 127
The Oracle 11g database is connecting fine, but no data is getting displayed in the GridView, Please help! The following code is in page load code
OracleConnection con = new OracleConnection();
con.ConnectionString = "DATA SOURCE=DEMODB;USER ID=SYSTEM;password=admin";
con.Open();
string sql = "select * from Insurance";
OracleCommand comm = new OracleCommand(sql, con);
OracleDataAdapter da = new OracleDataAdapter(comm);
DataSet ds = new DataSet();
da.Fill(ds, "Insurance");
GridView1.DataSource = ds.Tables["Insurance"];
GridView1.DataBind();
con.Close();
This is the source code of page:
</asp:Label>
<asp:GridView ID="GridView1" runat="server">
</asp:GridView>
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button" />
<asp:SqlDataSource ID="DataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
ProviderName="<%$ConnectionStrings:ConnectionString.ProviderName %>"
SelectCommand="SELECT "SSN", "RID", "EID", "TYPE", "COST" FROM "TREATMENT"">
</asp:SqlDataSource>
</div>
Upvotes: 0
Views: 340
Reputation: 4686
Try this in place of your Page_Load
code and remove the <asp:SqlDataSource
entirely.
DataTable results = new DataTable();
using (OracleConnection con = new OracleConnection("DATA SOURCE=DEMODB;USER ID=SYSTEM;password=admin") {
con.Open();
using (OracleCommand comm = new OracleCommand("select * from Insurance", con)) {
results.Load(comm.ExecuteReader());
}
}
GridView1.DataSource = results;
GridView1.DataBind();
The GridView should be as simple as:
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="true"></asp:GridView>
Upvotes: 0